Author: bodewig
Date: Thu Sep 29 13:52:19 2011
New Revision: 1177307
URL: http://svn.apache.org/viewvc?rev=1177307&view=rev
Log:
Make <move> use tryHardToDelete under the covers
Modified:
ant/core/trunk/WHATSNEW
ant/core/trunk/manual/Tasks/delete.html
ant/core/trunk/manual/Tasks/move.html
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Move.java
Modified: ant/core/trunk/WHATSNEW
URL:
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1177307&r1=1177306&r2=1177307&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Thu Sep 29 13:52:19 2011
@@ -118,9 +118,9 @@ 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.
+ * <delete> and <move> have 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=1177307&r1=1177306&r2=1177307&view=diff
==============================================================================
--- ant/core/trunk/manual/Tasks/delete.html (original)
+++ ant/core/trunk/manual/Tasks/delete.html Thu Sep 29 13:52:19 2011
@@ -174,7 +174,7 @@ in <strong>Directory-based Tasks</strong
<tr>
<td valign="top">performGCOnFailedDelete</td>
<td valign="top">
- If ant fails to delete a file or directory it will retry the
+ 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
Modified: ant/core/trunk/manual/Tasks/move.html
URL:
http://svn.apache.org/viewvc/ant/core/trunk/manual/Tasks/move.html?rev=1177307&r1=1177306&r2=1177307&view=diff
==============================================================================
--- ant/core/trunk/manual/Tasks/move.html (original)
+++ ant/core/trunk/manual/Tasks/move.html Thu Sep 29 13:52:19 2011
@@ -168,6 +168,19 @@ there is a directory by the same name in
on separate machines with clocks being out of sync. <em>since Ant
1.6</em>.</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 "true" on
+ Windows and "true" on any other OS.</td>
+ </tr>
</table>
<h3>Parameters specified as nested elements</h3>
<h4>mapper</h4>
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Move.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Move.java?rev=1177307&r1=1177306&r2=1177307&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Move.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Move.java Thu Sep 29
13:52:19 2011
@@ -24,6 +24,7 @@ import java.util.Iterator;
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.FilterSet;
import org.apache.tools.ant.types.FilterSetCollection;
@@ -51,6 +52,8 @@ import org.apache.tools.ant.types.Filter
*/
public class Move extends Copy {
+ private boolean performGc = Os.isFamily("windows");
+
/**
* Constructor of object.
* This sets the forceOverwrite attribute of the Copy parent class
@@ -62,6 +65,19 @@ public class Move extends Copy {
setOverwrite(true);
}
+ /**
+ * 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;
+ }
+
/** {@inheritDoc}. */
protected void validateAttributes() throws BuildException {
if (file != null && file.isDirectory()) {
@@ -204,7 +220,7 @@ public class Move extends Copy {
if (!moved) {
copyFile(fromFile, toFile, filtering, overwrite);
- if (!fromFile.delete()) {
+ if (!getFileUtils().tryHardToDelete(fromFile, performGc)) {
throw new BuildException("Unable to delete " + "file "
+ fromFile.getAbsolutePath());
}
@@ -293,7 +309,8 @@ public class Move extends Copy {
File f = new File(d, s);
if (f.isDirectory()) {
deleteDir(f);
- } else if (deleteFiles && !(f.delete())) {
+ } else if (deleteFiles && !getFileUtils().tryHardToDelete(f,
+
performGc)) {
throw new BuildException("Unable to delete file " +
f.getAbsolutePath());
} else {
throw new BuildException("UNEXPECTED ERROR - The file "
@@ -301,7 +318,7 @@ public class Move extends Copy {
}
}
log("Deleting directory " + d.getAbsolutePath(), verbosity);
- if (!d.delete()) {
+ if (!getFileUtils().tryHardToDelete(d, performGc)) {
throw new BuildException("Unable to delete directory " +
d.getAbsolutePath());
}
}
@@ -355,7 +372,8 @@ public class Move extends Copy {
+ " is a no-op.", Project.MSG_VERBOSE);
return true;
}
- if (!(getFileUtils().areSame(sourceFile, destFile) ||
destFile.delete())) {
+ if (!(getFileUtils().areSame(sourceFile, destFile)
+ || getFileUtils().tryHardToDelete(destFile, performGc))) {
throw new BuildException("Unable to remove existing file " +
destFile);
}
}