Skip to content

Commit

Permalink
Windows: Create a dangling junction when symlink target doesn't exist
Browse files Browse the repository at this point in the history
On Unix system, `ln -s foo bar` will create an dangling symlink bar -> foo
even foo doesn't exist. The current implementation of createSymbolicLink for
Windows fails in this situtation. And this lead to #2474.

In this change, we create a dangling junction when the target doesn't exist
which mimics the behavior on Unix.

Fixed #2474

Change-Id: I442ca3e2fb20b76c9b5bbfee903299fe51481f43
PiperOrigin-RevId: 157694631
  • Loading branch information
meteorcloudy authored and laszlocsomor committed Jun 1, 2017
1 parent a4697fd commit 6c07525
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,8 @@ protected void createSymbolicLink(Path linkPath, PathFragment targetFragment) th
try {
java.nio.file.Path link = getIoFile(linkPath).toPath();
java.nio.file.Path target = getIoFile(targetPath).toPath();
if (target.toFile().isDirectory()) {
// Still Create a dangling junction if the target doesn't exist.
if (!target.toFile().exists() || target.toFile().isDirectory()) {
WindowsFileOperations.createJunction(link.toString(), target.toString());
} else {
Files.copy(target, link);
Expand Down

0 comments on commit 6c07525

Please sign in to comment.