Browse Source

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

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1177305 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 13 years ago
parent
commit
ececc5c3e3
4 changed files with 46 additions and 3 deletions
  1. +5
    -0
      WHATSNEW
  2. +13
    -0
      manual/Tasks/delete.html
  3. +16
    -1
      src/main/org/apache/tools/ant/taskdefs/Delete.java
  4. +12
    -2
      src/main/org/apache/tools/ant/util/FileUtils.java

+ 5
- 0
WHATSNEW View File

@@ -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
===================================



+ 13
- 0
manual/Tasks/delete.html View File

@@ -171,6 +171,19 @@ in <strong>Directory-based Tasks</strong>, and see the
<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>


+ 16
- 1
src/main/org/apache/tools/ant/taskdefs/Delete.java View File

@@ -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."


+ 12
- 2
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -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>


Loading…
Cancel
Save