|
|
@@ -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.FilterSetCollection; |
|
|
|
*/ |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
|