From 4216b1a4ccd21fc290f2a5f1f9d96a83c18d051c Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Tue, 9 Nov 2004 16:11:36 +0000 Subject: [PATCH] Improve code as suggested by Dominique git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@277007 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/org/apache/tools/ant/taskdefs/Sync.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Sync.java b/src/main/org/apache/tools/ant/taskdefs/Sync.java index e890c1fc4..2f4282506 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Sync.java +++ b/src/main/org/apache/tools/ant/taskdefs/Sync.java @@ -152,9 +152,10 @@ public class Sync extends Task { 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 @@ public class Sync extends Task { ++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);