On Fri, 02 Nov 2001 Stefan Bodewig wrote :
> In the current
> situation many directories will not be scanned at all 
> (the fast mode),
> but if we apply your patch, all directories will be 
> scanned.

I see what you mean.  I am submitting a patch alongwith
that does not result in slowscan being called.  The
reason why I had invoked getNotIncludedDirectories
and getNotIncludedFiles in the earlier patch was to just 
find out if at all there are any notincluded 
files/dirs.  But with this patch, I work around the
need for calling these two methods by introducing a new
method - isNotIncludedAvailable which by default is false
but gets set to true in scandir if it meets certain
conditions.  Let me know if this would still slow
down selective files based copy/move tasks.

Magesh

 
cvs diff -u DirectoryScanner.java 
Index: DirectoryScanner.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/DirectoryScanner.java,v
retrieving revision 1.17
diff -u -r1.17 DirectoryScanner.java
--- DirectoryScanner.java       2001/10/28 21:25:26     1.17
+++ DirectoryScanner.java       2001/11/02 22:31:43
@@ -218,6 +218,8 @@
      */
     protected boolean isCaseSensitive = true;
 
+    protected boolean notIncludedAvailable = false;
+
     /**
      * Constructor.
      */
@@ -522,7 +524,7 @@
             }
             return true; // String matches against pattern
         }
-        
+
         if (patIdxEnd == 0) {
             return true; // Pattern contains only '*', which matches anything
         }
@@ -735,6 +737,9 @@
         }
     }
 
+    public boolean isNotIncludedAvailable() {
+        return notIncludedAvailable;
+    }
 
 
     /**
@@ -802,14 +807,14 @@
 
         for (int i=0; i<excl.length; i++) {
             if (!couldHoldIncluded(excl[i])) {
-                scandir(new File(basedir, excl[i]), 
+                scandir(new File(basedir, excl[i]),
                         excl[i]+File.separator, false);
             }
         }
-        
+
         for (int i=0; i<notIncl.length; i++) {
             if (!couldHoldIncluded(notIncl[i])) {
-                scandir(new File(basedir, notIncl[i]), 
+                scandir(new File(basedir, notIncl[i]),
                         notIncl[i]+File.separator, false);
             }
         }
@@ -843,7 +848,7 @@
              * two reasons are mentioned in the API docs for File.list
              * (1) dir is not a directory. This is impossible as
              *     we wouldn't get here in this case.
-             * (2) an IO error occurred (why doesn't it throw an exception 
+             * (2) an IO error occurred (why doesn't it throw an exception
              *     then???)
              */
             throw new BuildException("IO error scanning directory "
@@ -867,6 +872,7 @@
                         }
                     }
                 } else {
+                    notIncludedAvailable = true;
                     dirsNotIncluded.addElement(name);
                     if (fast && couldHoldIncluded(name)) {
                         scandir(file, name+File.separator, fast);
@@ -883,6 +889,7 @@
                         filesExcluded.addElement(name);
                     }
                 } else {
+                    notIncludedAvailable = true;
                     filesNotIncluded.addElement(name);
                 }
             }






cvs diff -u Copy.java 
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 -r1.22 Copy.java
--- Copy.java   2001/10/28 21:26:29     1.22
+++ Copy.java   2001/11/02 22:32:36
@@ -75,13 +75,13 @@
 import java.util.Enumeration;
 
 /**
- * A consolidated copy task.  Copies a file or directory to a new file 
+ * A consolidated copy task.  Copies a file or directory to a new file
  * or directory.  Files are only copied if the source file is newer
- * than the destination file, or when the destination file does not 
+ * than the destination file, or when the destination file does not
  * exist.  It is possible to explicitly overwrite existing files.</p>
  *
  * <p>This implementation is based on Arnout Kuiper's initial design
- * document, the following mailing list discussions, and the 
+ * document, the following mailing list discussions, and the
  * copyfile/copydir tasks.</p>
  *
  * @author Glenn McAllister <a href="mailto:[EMAIL PROTECTED]">[EMAIL 
PROTECTED]</a>
@@ -90,8 +90,8 @@
  * @author <a href="mailto:[EMAIL PROTECTED]">Magesh Umasankar</a>
  */
 public class Copy extends Task {
-    protected File file = null;     // the source file 
-    protected File destFile = null; // the destination file 
+    protected File file = null;     // the source file
+    protected File destFile = null; // the destination file
     protected File destDir = null;  // the destination directory
     protected Vector filesets = new Vector();
 
@@ -104,11 +104,12 @@
 
     protected Hashtable fileCopyMap = new Hashtable();
     protected Hashtable dirCopyMap = new Hashtable();
+    protected Hashtable completeDirMap = new Hashtable();
 
     protected Mapper mapperElement = null;
     private Vector filterSets = new Vector();
     private FileUtils fileUtils;
-    
+
     public Copy() {
         fileUtils = FileUtils.newFileUtils();
     }
@@ -144,7 +145,7 @@
         filterSets.addElement(filterSet);
         return filterSet;
     }
-    
+
     /**
      * Give the copied files the same last modified time as the original files.
      */
@@ -160,7 +161,7 @@
     protected Vector getFilterSets() {
         return filterSets;
     }
-    
+
     /**
      * Sets filtering.
      */
@@ -194,8 +195,8 @@
             this.verbosity = Project.MSG_INFO;
         } else {
             this.verbosity = Project.MSG_VERBOSE;
-        } 
-    } 
+        }
+    }
 
     /**
      * Used to copy empty directories.
@@ -228,7 +229,7 @@
      */
     public void execute() throws BuildException {
         // make sure we don't have an illegal set of options
-        validateAttributes();   
+        validateAttributes();
 
         // deal with the single file
         if (file != null) {
@@ -236,8 +237,8 @@
                 if (destFile == null) {
                     destFile = new File(destDir, file.getName());
                 }
-                
-                if (forceOverwrite || 
+
+                if (forceOverwrite ||
                     (file.lastModified() > destFile.lastModified())) {
                     fileCopyMap.put(file.getAbsolutePath(), 
destFile.getAbsolutePath());
                 } else {
@@ -245,7 +246,7 @@
                         Project.MSG_VERBOSE);
                 }
             } else {
-                String message = "Could not find file " 
+                String message = "Could not find file "
                                  + file.getAbsolutePath() + " to copy.";
                 log(message);
                 throw new BuildException(message);
@@ -260,7 +261,11 @@
 
             String[] srcFiles = ds.getIncludedFiles();
             String[] srcDirs = ds.getIncludedDirectories();
-
+            boolean notIncludedAvailable = ds.isNotIncludedAvailable();
+            if (!notIncludedAvailable
+                && !flatten && mapperElement == null) {
+                completeDirMap.put(fromDir, destDir);
+            }
             scan(fromDir, destDir, srcFiles, srcDirs);
         }
 
@@ -280,7 +285,7 @@
 
     /**
      * Ensure we have a consistent and legal set of attributes, and set
-     * any internal flags necessary based on different combinations 
+     * any internal flags necessary based on different combinations
      * of attributes.
      */
     protected void validateAttributes() throws BuildException {
@@ -299,7 +304,7 @@
         if (file != null && file.exists() && file.isDirectory()) {
             throw new BuildException("Use a fileset to copy directories.");
         }
-           
+
         if (destFile != null && filesets.size() > 0) {
             if (filesets.size() > 1) {
                 throw new BuildException(
@@ -368,7 +373,7 @@
             SourceFileScanner ds = new SourceFileScanner(this);
             toCopy = ds.restrict(names, fromDir, toDir, mapper);
         }
-        
+
         for (int i = 0; i < toCopy.length; i++) {
             File src = new File(fromDir, toCopy[i]);
             File dest = new File(toDir, mapper.mapFileName(toCopy[i])[0]);
@@ -382,8 +387,8 @@
      */
     protected void doFileOperations() {
         if (fileCopyMap.size() > 0) {
-            log("Copying " + fileCopyMap.size() + 
-                " file" + (fileCopyMap.size() == 1 ? "" : "s") + 
+            log("Copying " + fileCopyMap.size() +
+                " file" + (fileCopyMap.size() == 1 ? "" : "s") +
                 " to " + destDir.getAbsolutePath() );
 
             Enumeration e = fileCopyMap.keys();
@@ -398,7 +403,7 @@
 
                 try {
                     log("Copying " + fromFile + " to " + toFile, verbosity);
-                    
+
                     FilterSetCollection executionFilters = new 
FilterSetCollection();
                     if (filtering) {
                         
executionFilters.addFilterSet(project.getGlobalFilterSet());
@@ -431,9 +436,9 @@
             }
 
             if (count > 0) {
-                log("Copied " + count + 
-                    " empty director" + 
-                    (count==1?"y":"ies") + 
+                log("Copied " + count +
+                    " empty director" +
+                    (count==1?"y":"ies") +
                     " to " + destDir.getAbsolutePath());
             }
         }




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/02 22:33:19
@@ -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]>

Reply via email to