The move task, as it is now, does not optimally perform
moves of entire directories. For example, if directory
A is to be moved to directory B, all files in directory
A are moved to directory B one by one recursively,
thereby accomplishing the directory move.
If the directory itself can be renamed instead of
taking the above approach, it will greatly improve
performance.
This patch does precisely that when 'normal' directory
moves are performed. It operates at the fileset level.
Each fileset that has an empty 'notIncluded' file/dir
list is treated as a candidate for a dir rename since
this means that all files in the dir has been included.
Of course, if flatten or mappers are being used, a
straight forward directory rename isn't attempted.
Magesh
Index: Copy.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Copy.java,v
retrieving revision 1.22
diff -u -w -r1.22 Copy.java
--- Copy.java 2001/10/28 21:26:29 1.22
+++ Copy.java 2001/11/01 02:26:08
@@ -104,6 +104,7 @@
protected Hashtable fileCopyMap = new Hashtable();
protected Hashtable dirCopyMap = new Hashtable();
+ protected Hashtable completeDirMap = new Hashtable();
protected Mapper mapperElement = null;
private Vector filterSets = new Vector();
@@ -260,7 +261,12 @@
String[] srcFiles = ds.getIncludedFiles();
String[] srcDirs = ds.getIncludedDirectories();
-
+ String[] notIncludedFiles = ds.getNotIncludedFiles();
+ String[] notIncludedDirs = ds.getNotIncludedDirectories();
+ if (notIncludedFiles.length == 0 && notIncludedDirs.length == 0
+ && !flatten && mapperElement == null) {
+ completeDirMap.put(fromDir, destDir);
+ }
scan(fromDir, destDir, srcFiles, srcDirs);
}
****************************
cvs diff -u Move.java
Index: Move.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Move.java,v
retrieving revision 1.9
diff -u -r1.9 Move.java
--- Move.java 2001/10/28 21:26:29 1.9
+++ Move.java 2001/11/01 02:11:54
@@ -94,6 +94,24 @@
//************************************************************************
protected void doFileOperations() {
+ //Attempt complete directory renames, if any, first.
+ if (completeDirMap.size() > 0) {
+ Enumeration e = completeDirMap.keys();
+ while (e.hasMoreElements()) {
+ File fromDir = (File) e.nextElement();
+ File toDir = (File) completeDirMap.get(fromDir);
+ try {
+ log("Attempting to rename dir: " + fromDir +
+ " to " + toDir, verbosity);
+ renameFile(fromDir, toDir, filtering, forceOverwrite);
+ } catch (IOException ioe) {
+ String msg = "Failed to rename dir " + fromDir
+ + " to " + toDir
+ + " due to " + ioe.getMessage();
+ throw new BuildException(msg, ioe, location);
+ }
+ }
+ }
if (fileCopyMap.size() > 0) { // files to move
log("Moving " + fileCopyMap.size() + " files to " +
destDir.getAbsolutePath() );
@@ -110,44 +128,47 @@
boolean moved = false;
File f = new File(fromFile);
- File d = new File(toFile);
- try {
- log("Attempting to rename: " + fromFile +
- " to " + toFile, verbosity);
- moved = renameFile(f, d, filtering, forceOverwrite);
- } catch (IOException ioe) {
- String msg = "Failed to rename " + fromFile
- + " to " + toFile
- + " due to " + ioe.getMessage();
- throw new BuildException(msg, ioe, location);
- }
+ if (f.exists()) { //Is this file still available to be moved?
+ File d = new File(toFile);
- if (!moved) {
try {
- log("Moving " + fromFile + " to " + toFile, verbosity);
-
- FilterSetCollection executionFilters = new
FilterSetCollection();
- if (filtering) {
-
executionFilters.addFilterSet(project.getGlobalFilterSet());
- }
- for (Enumeration filterEnum =
getFilterSets().elements(); filterEnum.hasMoreElements();) {
-
executionFilters.addFilterSet((FilterSet)filterEnum.nextElement());
- }
- getFileUtils().copyFile(f, d, executionFilters,
- forceOverwrite);
-
- f = new File(fromFile);
- if (!f.delete()) {
- throw new BuildException("Unable to delete file "
- + f.getAbsolutePath());
- }
+ log("Attempting to rename: " + fromFile +
+ " to " + toFile, verbosity);
+ moved = renameFile(f, d, filtering, forceOverwrite);
} catch (IOException ioe) {
- String msg = "Failed to copy " + fromFile + " to "
- + toFile
+ String msg = "Failed to rename " + fromFile
+ + " to " + toFile
+ " due to " + ioe.getMessage();
throw new BuildException(msg, ioe, location);
}
+
+ if (!moved) {
+ try {
+ log("Moving " + fromFile + " to " + toFile,
verbosity);
+
+ FilterSetCollection executionFilters = new
FilterSetCollection();
+ if (filtering) {
+
executionFilters.addFilterSet(project.getGlobalFilterSet());
+ }
+ for (Enumeration filterEnum =
getFilterSets().elements(); filterEnum.hasMoreElements();) {
+
executionFilters.addFilterSet((FilterSet)filterEnum.nextElement());
+ }
+ getFileUtils().copyFile(f, d, executionFilters,
+ forceOverwrite);
+
+ f = new File(fromFile);
+ if (!f.delete()) {
+ throw new BuildException("Unable to delete
file "
+ +
f.getAbsolutePath());
+ }
+ } catch (IOException ioe) {
+ String msg = "Failed to copy " + fromFile + " to "
+ + toFile
+ + " due to " + ioe.getMessage();
+ throw new BuildException(msg, ioe, location);
+ }
+ }
}
}
}
@@ -255,7 +276,7 @@
if (destFile.exists()) {
if (!destFile.delete()) {
- throw new BuildException("Unable to remove existing file "
+ throw new BuildException("Unable to remove existing file "
+ destFile);
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>