ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1177305 - in /ant/core/trunk: WHATSNEW manual/Tasks/delete.html src/main/org/apache/tools/ant/taskdefs/Delete.java src/main/org/apache/tools/ant/util/FileUtils.java
Date Thu, 29 Sep 2011 13:40:56 GMT
Author: bodewig
Date: Thu Sep 29 13:40:56 2011
New Revision: 1177305

URL: http://svn.apache.org/viewvc?rev=1177305&view=rev
Log:
Add an option to <delete> to run the GC before retrying a failed build on non-Windows
OSes as well.  Might fix the NFS problem described in PR 45786

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/manual/Tasks/delete.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java
    ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1177305&r1=1177304&r2=1177305&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Thu Sep 29 13:40:56 2011
@@ -118,6 +118,11 @@ Other changes:
 
  * Provide read access to Mkdir.dir.  Bugzilla Report 51684.
 
+ * <delete> has a new attribute performGCOnFailedDelete that may -
+   when set to true - help resolve some problems with deleting empty
+   directories on NFS shares.
+   Bugzilla Report 45807.
+
 Changes from Ant 1.8.1 TO Ant 1.8.2
 ===================================
 

Modified: ant/core/trunk/manual/Tasks/delete.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/manual/Tasks/delete.html?rev=1177305&r1=1177304&r2=1177305&view=diff
==============================================================================
--- ant/core/trunk/manual/Tasks/delete.html (original)
+++ ant/core/trunk/manual/Tasks/delete.html Thu Sep 29 13:40:56 2011
@@ -171,6 +171,19 @@ in <strong>Directory-based Tasks</strong
       <em>Since Ant 1.8.0</em></td>
     <td align="center" valign="top">No, default &quot;false&quot;</td>
   </tr>
+  <tr>
+    <td valign="top">performGCOnFailedDelete</td>
+    <td valign="top">
+      If ant fails to delete a file or directory it will retry the
+      operation once.  If this flag is set to true it will perform a
+      garbage collection before retrying the delete.<br/>
+      Setting this flag to true is known to resolve some problems on
+      Windows (where it defaults to true) but also for directory trees
+      residing on an NFS share.
+      <em>Since Ant 1.8.3</em></td>
+    <td align="center" valign="top">No, default &quot;true&quot; on
+      Windows and &quot;true&quot; on any other OS.</td>
+  </tr>
 </table>
 
 <h3>Examples</h3>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java?rev=1177305&r1=1177304&r2=1177305&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Delete.java Thu Sep 29 13:40:56
2011
@@ -27,6 +27,7 @@ import java.util.Comparator;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.taskdefs.condition.Os;
 import org.apache.tools.ant.types.FileSet;
 import org.apache.tools.ant.types.PatternSet;
 import org.apache.tools.ant.types.Resource;
@@ -119,6 +120,7 @@ public class Delete extends MatchingTask
     private static FileUtils FILE_UTILS = FileUtils.getFileUtils();
     private static SymbolicLinkUtils SYMLINK_UTILS =
         SymbolicLinkUtils.getSymbolicLinkUtils();
+    private boolean performGc = Os.isFamily("windows");
 
     /**
      * Set the name of a single file to be removed.
@@ -197,6 +199,19 @@ public class Delete extends MatchingTask
         this.includeEmpty = includeEmpty;
     }
 
+    /**
+     * Whether to perform a garbage collection before retrying a failed delete.
+     *
+     * <p>This may be required on Windows (where it is set to true by
+     * default) but also on other operating systems, for example when
+     * deleting directories from an NFS share.</p>
+     *
+     * @since Ant 1.8.3
+     */
+    public void setPerformGcOnFailedDelete(boolean b) {
+        performGc = b;
+    }
+
    /**
     * Adds a set of files to be deleted.
     * @param set the set of files to be deleted
@@ -719,7 +734,7 @@ public class Delete extends MatchingTask
      * wait a little and try again.
      */
     private boolean delete(File f) {
-        if (!FILE_UTILS.tryHardToDelete(f)) {
+        if (!FILE_UTILS.tryHardToDelete(f, performGc)) {
             if (deleteOnExit) {
                 int level = quiet ? Project.MSG_VERBOSE : Project.MSG_INFO;
                 log("Failed to delete " + f + ", calling deleteOnExit."

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java?rev=1177305&r1=1177304&r2=1177305&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java Thu Sep 29 13:40:56 2011
@@ -1562,8 +1562,19 @@ public class FileUtils {
      * @since Ant 1.8.0
      */
     public boolean tryHardToDelete(File f) {
+        return tryHardToDelete(f, ON_WINDOWS);
+    }
+
+    /**
+     * If delete does not work, call System.gc() if asked to, wait a
+     * little and try again.
+     *
+     * @return whether deletion was successful
+     * @since Ant 1.8.3
+     */
+    public boolean tryHardToDelete(File f, boolean runGC) {
         if (!f.delete()) {
-            if (ON_WINDOWS) {
+            if (runGC) {
                 System.gc();
             }
             try {
@@ -1576,7 +1587,6 @@ public class FileUtils {
         return true;
     }
 
-
     /**
      * Calculates the relative path between two files.
      * <p>



Mime
View raw message