Browse Source

allow symlink to delete broken links. Part of PR 41285.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@692047 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 17 years ago
parent
commit
8ea8f38c22
3 changed files with 19 additions and 2 deletions
  1. +5
    -0
      WHATSNEW
  2. +7
    -2
      src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java
  3. +7
    -0
      src/tests/antunit/taskdefs/optional/unix/symlink-test.xml

+ 5
- 0
WHATSNEW View File

@@ -91,6 +91,11 @@ Changes that could break older environments:
locale.
Bugzilla Report 44659.

* <symlink action="delete"> used to fail if the link was broken (i.e.
pointing to a file or directory that no longer existed). It will now
silently try to remove the link.
Bugzilla Report 41285.

Fixed bugs:
-----------



+ 7
- 2
src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java View File

@@ -391,7 +391,11 @@ public class Symlink extends DispatchTask {
* 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.
* an exception.</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>
*
* @param linkfil A <code>File</code> object of the symlink to delete.
*
@@ -403,7 +407,8 @@ public class Symlink extends DispatchTask {
public static void deleteSymlink(File linkfil)
throws IOException {
if (!linkfil.exists()) {
throw new FileNotFoundException("No such symlink: " + linkfil);
linkfil.delete();
return;
}
// find the resource of the existing link:
File canfil = linkfil.getCanonicalFile();


+ 7
- 0
src/tests/antunit/taskdefs/optional/unix/symlink-test.xml View File

@@ -62,4 +62,11 @@
resource="${file_ref}"/>
</target>

<target name="testDeleteOfBrokenLink" depends="init" if="unix">
<symlink link="${output}/link" resource="${file_ref}"/>
<delete file="${file_ref}"/>
<symlink link="${output}/link" action="delete"/>
<au:assertFileDoesntExist file="${output}/link"/>
</target>

</project>

Loading…
Cancel
Save