IVY-1594 Make sure we unlink an existing link, when retrieve task is enabled with...
authorJaikiran Pai <jaikiran@apache.org>
Thu, 6 Dec 2018 00:52:31 +0000 (06:22 +0530)
committerJaikiran Pai <jaikiran@apache.org>
Thu, 6 Dec 2018 00:52:31 +0000 (06:22 +0530)
src/java/org/apache/ivy/util/FileUtil.java

index 2968708..9c780f2 100644 (file)
@@ -85,9 +85,17 @@ public final class FileUtil {
                 return false;
             }
         } else {
-            // it's a directory being symlinked, make sure the "link" that is being
-            // created has the necessary parent directories in place before triggering
-            // symlink creation
+            // it's a directory being symlinked
+
+            // see if the directory represented by the "link" exists and is already a symbolic
+            // link. If it is and if we are asked to overwrite then we *only* break the link
+            // in preparation of symlink creation, later in this method
+            if (Files.isSymbolicLink(link.toPath()) && overwrite) {
+                Message.verbose("Un-linking existing symbolic link " + link + " during symlink creation, since overwrite=true");
+                Files.delete(link.toPath());
+            }
+            // make sure the "link" that is being created has the necessary parent directories
+            // in place before triggering symlink creation
             if (link.getParentFile() != null) {
                 link.getParentFile().mkdirs();
             }