From 8e0991cb19eadfcb651cd6987255d5f7c0a58e0a Mon Sep 17 00:00:00 2001 From: Yun Peng Date: Tue, 7 Feb 2017 09:42:36 +0000 Subject: WindowsFileSystem.java: Fix createSymbolicLink when target is a relative path Fixed https://github.com/bazelbuild/bazel/issues/2494 -- Change-Id: I2ca335fa5b3a7759f57085717128912f09363789 Reviewed-on: https://cr.bazel.build/8650 PiperOrigin-RevId: 146761747 MOS_MIGRATED_REVID=146761747 --- .../java/com/google/devtools/build/lib/vfs/WindowsFileSystem.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/main/java/com/google/devtools/build/lib/vfs') diff --git a/src/main/java/com/google/devtools/build/lib/vfs/WindowsFileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/WindowsFileSystem.java index 308e0dfc66..7a144f5c3e 100644 --- a/src/main/java/com/google/devtools/build/lib/vfs/WindowsFileSystem.java +++ b/src/main/java/com/google/devtools/build/lib/vfs/WindowsFileSystem.java @@ -335,7 +335,12 @@ public class WindowsFileSystem extends JavaIoFileSystem { if (targetFile.isDirectory()) { createDirectoryJunction(targetFile, file); } else { - Files.copy(targetFile.toPath(), file.toPath()); + if (targetFile.isAbsolute()) { + Files.copy(targetFile.toPath(), file.toPath()); + } else { + // When targetFile is a relative path to linkPath, resolve it to an absolute path first. + Files.copy(file.toPath().getParent().resolve(targetFile.toPath()), file.toPath()); + } } } catch (java.nio.file.FileAlreadyExistsException e) { throw new IOException(linkPath + ERR_FILE_EXISTS); -- cgit v1.2.3