Browse Source

Improve code as suggested by Dominique

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277007 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 21 years ago
parent
commit
4216b1a4cc
1 changed files with 9 additions and 3 deletions
  1. +9
    -3
      src/main/org/apache/tools/ant/taskdefs/Sync.java

+ 9
- 3
src/main/org/apache/tools/ant/taskdefs/Sync.java View File

@@ -152,9 +152,10 @@ public class Sync extends Task {
int[] removedCount = new int[] {0, 0}; int[] removedCount = new int[] {0, 0};
DirectoryScanner ds = new DirectoryScanner(); DirectoryScanner ds = new DirectoryScanner();
ds.setBasedir(toDir); 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.setExcludes(excls);
ds.scan(); ds.scan();
String[] files = ds.getIncludedFiles(); String[] files = ds.getIncludedFiles();
@@ -165,6 +166,11 @@ public class Sync extends Task {
++removedCount[1]; ++removedCount[1];
} }
String[] dirs = ds.getIncludedDirectories(); 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) { for (int i = dirs.length - 1 ; i >= 0 ; --i) {
File f = new File(toDir, dirs[i]); File f = new File(toDir, dirs[i]);
log("Removing orphan directory: " + f, Project.MSG_DEBUG); log("Removing orphan directory: " + f, Project.MSG_DEBUG);


Loading…
Cancel
Save