Skip to content

Commit c9d5727

Browse files
mkargolamy
authored andcommitted
bug fix: silently fails overwriting symlinks (#13)
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 06a5df9 commit c9d5727

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

Lines changed: 4 additions & 3 deletions
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)