diff options
author | Stefan Bodewig <bodewig@apache.org> | 2008-09-04 14:57:04 +0000 |
---|---|---|
committer | Stefan Bodewig <bodewig@apache.org> | 2008-09-04 14:57:04 +0000 |
commit | 5348fe6bcba126301a3f97e3919f7eeca1b940ea (patch) | |
tree | a7ee2e5ddf375099a1080e35d9d0accccfa65893 /src/main/org/apache/tools/ant/taskdefs/optional/unix | |
parent | 8ea8f38c22dce6c8c6696751ae6c381e4f1985fa (diff) | |
download | ant-5348fe6bcba126301a3f97e3919f7eeca1b940ea.tar.gz |
symlink delete now works if the link points to a parent directory as well. PR 45743.
git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@692081 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/main/org/apache/tools/ant/taskdefs/optional/unix')
-rw-r--r-- | src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java b/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java index 0d2d2b2e5..c64b8225d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java @@ -386,13 +386,19 @@ public class Symlink extends DispatchTask { * <p>This is a utility method that removes a unix symlink without removing * the resource that the symlink points to. If it is accidentally invoked * on a real file, the real file will not be harmed, but an exception - * will be thrown when the deletion is attempted. This method works by + * will be thrown when the deletion is attempted.</p> + * + * <p>Normaly this method works by * getting the canonical path of the link, using the canonical path to * rename the resource (breaking the link) and then deleting the link. * The resource is then returned to its original name inside a finally * block to ensure that the resource is unharmed even in the event of * an exception.</p> * + * <p>There may be cases where the algorithm described above doesn't work, + * in that case the method tries to use the native "rm" command on + * the symlink instead.</p> + * * <p>Since Ant 1.8.0 this method will try to delete the File object if * it reports it wouldn't exist (as symlinks pointing nowhere usually do). * Prior version would throw a FileNotFoundException in that case.</p> @@ -410,12 +416,22 @@ public class Symlink extends DispatchTask { linkfil.delete(); return; } + // find the resource of the existing link: File canfil = linkfil.getCanonicalFile(); // rename the resource, thus breaking the link: File temp = FILE_UTILS.createTempFile("symlink", ".tmp", - canfil.getParentFile(), false, false); + canfil.getParentFile(), false, + false); + + if (FILE_UTILS.isLeadingPath(canfil, linkfil)) { + // link points to a parent directory, renaming the parent + // will rename the file + linkfil = new File(temp, + FILE_UTILS.removeLeadingPath(canfil, linkfil)); + } + try { try { FILE_UTILS.rename(canfil, temp); |