bodewig 2004/11/09 08:11:36 Modified: src/main/org/apache/tools/ant/taskdefs Sync.java Log: Improve code as suggested by Dominique Revision Changes Path 1.15 +10 -4 ant/src/main/org/apache/tools/ant/taskdefs/Sync.java Index: Sync.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Sync.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- Sync.java 9 Nov 2004 10:19:51 -0000 1.14 +++ Sync.java 9 Nov 2004 16:11:36 -0000 1.15 @@ -152,9 +152,10 @@ int[] removedCount = new int[] {0, 0}; DirectoryScanner ds = new DirectoryScanner(); ds.setBasedir(toDir); - Set s = new HashSet(nonOrphans); - s.add(""); - String[] excls = (String[]) s.toArray(new String[s.size()]); + String[] excls = + (String[]) nonOrphans.toArray(new String[nonOrphans.size() + 1]); + // want to keep toDir itself + excls[nonOrphans.size()] = ""; ds.setExcludes(excls); ds.scan(); String[] files = ds.getIncludedFiles(); @@ -165,6 +166,11 @@ ++removedCount[1]; } String[] dirs = ds.getIncludedDirectories(); + // ds returns the directories as it has visited them. + // iterating through the array backwards means we are deleting + // leaves before their parent nodes - thus making sure (well, + // more likely) that the directories are empty when we try to + // delete them. for (int i = dirs.length - 1 ; i >= 0 ; --i) { File f = new File(toDir, dirs[i]); log("Removing orphan directory: " + f, Project.MSG_DEBUG);
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]