From 8ea8f38c22dce6c8c6696751ae6c381e4f1985fa Mon Sep 17 00:00:00 2001
From: Stefan Bodewig
Date: Thu, 4 Sep 2008 14:28:04 +0000
Subject: [PATCH] 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
---
WHATSNEW | 5 +++++
.../apache/tools/ant/taskdefs/optional/unix/Symlink.java | 9 +++++++--
.../antunit/taskdefs/optional/unix/symlink-test.xml | 7 +++++++
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/WHATSNEW b/WHATSNEW
index f01fb84e0..1f25ac778 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -91,6 +91,11 @@ Changes that could break older environments:
locale.
Bugzilla Report 44659.
+ * 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:
-----------
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 9cd296746..0d2d2b2e5 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
@@ -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.
+ *
+ * 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.
*
* @param linkfil A File 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();
diff --git a/src/tests/antunit/taskdefs/optional/unix/symlink-test.xml b/src/tests/antunit/taskdefs/optional/unix/symlink-test.xml
index 95b669f53..2a1cdfa02 100644
--- a/src/tests/antunit/taskdefs/optional/unix/symlink-test.xml
+++ b/src/tests/antunit/taskdefs/optional/unix/symlink-test.xml
@@ -62,4 +62,11 @@
resource="${file_ref}"/>
+
+
+
+
+
+
+