Skip to content

Commit 43fb825

Browse files
committed
bug fix: silently fails overwriting symlinks
When A is an existing symlink to B, then createSymbolicLink(A,C) does neither overwrite A->B by A->C (as expected in analogy to the behavior of copy(A,C)) nor does it throw an exception nor does it return A->B to indicate the failure, but it actually "silently fails", i. e. it returns A->C! This certainly is heavily problematic, unsymmetric to what copy(File,File) and Files.createSymbolicLink(Path,Path) do, and certainly unwanted and buggy behavior. The solution is to delete any existing target before creating the symlic, hence copying the behavior of copy(File,File).
1 parent 658fb00 commit 43fb825

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/main/java/org/codehaus/plexus/util/NioFiles.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,11 @@ public static File createSymbolicLink( File symlink, File target )
120120
throws IOException
121121
{
122122
Path link = symlink.toPath();
123-
if ( !Files.exists( link, LinkOption.NOFOLLOW_LINKS ) )
123+
if ( Files.exists( link, LinkOption.NOFOLLOW_LINKS ) )
124124
{
125-
link = Files.createSymbolicLink( link, target.toPath() );
125+
Files.delete( link );
126126
}
127+
link = Files.createSymbolicLink( link, target.toPath() );
127128
return link.toFile();
128129
}
129130

@@ -144,4 +145,4 @@ public static File copy( File source, File target )
144145
}
145146

146147

147-
}
148+
}

0 commit comments

Comments
 (0)