From 43fb825e405056e74eb2556d1629118ecc42209d Mon Sep 17 00:00:00 2001 From: Markus KARG Date: Sat, 28 May 2016 00:59:40 +0200 Subject: [PATCH] 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). --- src/main/java/org/codehaus/plexus/util/NioFiles.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/util/NioFiles.java b/src/main/java/org/codehaus/plexus/util/NioFiles.java index 18c12954..c31fb88f 100644 --- a/src/main/java/org/codehaus/plexus/util/NioFiles.java +++ b/src/main/java/org/codehaus/plexus/util/NioFiles.java @@ -120,10 +120,11 @@ public static File createSymbolicLink( File symlink, File target ) throws IOException { Path link = symlink.toPath(); - if ( !Files.exists( link, LinkOption.NOFOLLOW_LINKS ) ) + if ( Files.exists( link, LinkOption.NOFOLLOW_LINKS ) ) { - link = Files.createSymbolicLink( link, target.toPath() ); + Files.delete( link ); } + link = Files.createSymbolicLink( link, target.toPath() ); return link.toFile(); } @@ -144,4 +145,4 @@ public static File copy( File source, File target ) } -} \ No newline at end of file +}