Browse Source

now that slowScan is fixed, I realized that Sync cannot use it. Full implementation of PR 43159.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@728003 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
10f8a113ac
3 changed files with 44 additions and 4 deletions
  1. +25
    -4
      src/main/org/apache/tools/ant/taskdefs/Sync.java
  2. +10
    -0
      src/main/org/apache/tools/ant/types/AbstractFileSet.java
  3. +9
    -0
      src/tests/antunit/taskdefs/sync-test.xml

+ 25
- 4
src/main/org/apache/tools/ant/taskdefs/Sync.java View File

@@ -20,6 +20,7 @@ package org.apache.tools.ant.taskdefs;


import java.io.File; import java.io.File;


import java.util.Enumeration;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
@@ -189,10 +190,8 @@ public class Sync extends Task {


DirectoryScanner ds = null; DirectoryScanner ds = null;
if (syncTarget != null) { if (syncTarget != null) {
FileSet fs = new FileSet();
FileSet fs = syncTarget.toFileSet(false);
fs.setDir(toDir); fs.setDir(toDir);
fs.setCaseSensitive(syncTarget.isCaseSensitive());
fs.setFollowSymlinks(syncTarget.isFollowSymlinks());


// preserveInTarget would find all files we want to keep, // preserveInTarget would find all files we want to keep,
// but we need to find all that we want to delete - so the // but we need to find all that we want to delete - so the
@@ -245,7 +244,10 @@ public class Sync extends Task {


Boolean ped = getExplicitPreserveEmptyDirs(); Boolean ped = getExplicitPreserveEmptyDirs();
if (ped != null && ped.booleanValue() != myCopy.getIncludeEmptyDirs()) { if (ped != null && ped.booleanValue() != myCopy.getIncludeEmptyDirs()) {
String[] preservedDirs = ds.getExcludedDirectories();
FileSet fs = syncTarget.toFileSet(true);
fs.setDir(toDir);
String[] preservedDirs =
fs.getDirectoryScanner(getProject()).getIncludedDirectories();
for (int i = preservedDirs.length - 1; i >= 0; --i) { for (int i = preservedDirs.length - 1; i >= 0; --i) {
preservedDirectories.add(new File(toDir, preservedDirs[i])); preservedDirectories.add(new File(toDir, preservedDirs[i]));
} }
@@ -552,6 +554,25 @@ public class Sync extends Task {
public Boolean getPreserveEmptyDirs() { public Boolean getPreserveEmptyDirs() {
return preserveEmptyDirs; return preserveEmptyDirs;
} }

private FileSet toFileSet(boolean withPatterns) {
FileSet fs = new FileSet();
fs.setCaseSensitive(isCaseSensitive());
fs.setFollowSymlinks(isFollowSymlinks());
fs.setMaxLevelsOfSymlinks(getMaxLevelsOfSymlinks());
fs.setProject(getProject());

if (withPatterns) {
PatternSet ps = mergePatterns(getProject());
fs.appendIncludes(ps.getIncludePatterns(getProject()));
fs.appendExcludes(ps.getExcludePatterns(getProject()));
for (Enumeration e = selectorElements(); e.hasMoreElements(); ) {
fs.appendSelector((FileSelector) e.nextElement());
}
fs.setDefaultexcludes(getDefaultexcludes());
}
return fs;
}
} }


/** /**


+ 10
- 0
src/main/org/apache/tools/ant/types/AbstractFileSet.java View File

@@ -423,6 +423,16 @@ public abstract class AbstractFileSet extends DataType
maxLevelsOfSymlinks = max; maxLevelsOfSymlinks = max;
} }


/**
* The maximum number of times a symbolic link may be followed
* during a scan.
*
* @since Ant 1.8.0
*/
public int getMaxLevelsOfSymlinks() {
return maxLevelsOfSymlinks;
}

/** /**
* Sets whether an error is thrown if a directory does not exist. * Sets whether an error is thrown if a directory does not exist.
* *


+ 9
- 0
src/tests/antunit/taskdefs/sync-test.xml View File

@@ -20,7 +20,9 @@


<target name="setUp"> <target name="setUp">
<mkdir dir="${input}/a"/> <mkdir dir="${input}/a"/>
<mkdir dir="${input}/d"/>
<mkdir dir="${output}/a"/> <mkdir dir="${output}/a"/>
<mkdir dir="${output}/d"/>
<mkdir dir="${output}/b/c"/> <mkdir dir="${output}/b/c"/>
<touch file="${input}/a/foo.txt"/> <touch file="${input}/a/foo.txt"/>
<touch file="${output}/a/bar.txt"/> <touch file="${output}/a/bar.txt"/>
@@ -40,6 +42,7 @@
<au:assertFileExists file="${output}/a/foo.txt"/> <au:assertFileExists file="${output}/a/foo.txt"/>
<au:assertFileExists file="${output}/b/baz.txt"/> <au:assertFileExists file="${output}/b/baz.txt"/>
<au:assertFileExists file="${output}/b/c"/> <au:assertFileExists file="${output}/b/c"/>
<au:assertFileExists file="${output}/d"/>
</target> </target>


<target name="testDefaultDoesntPreserveEmptyDirs" depends="setUp"> <target name="testDefaultDoesntPreserveEmptyDirs" depends="setUp">
@@ -55,6 +58,7 @@
<au:assertFileExists file="${output}/a/foo.txt"/> <au:assertFileExists file="${output}/a/foo.txt"/>
<au:assertFileExists file="${output}/b/baz.txt"/> <au:assertFileExists file="${output}/b/baz.txt"/>
<au:assertFileDoesntExist file="${output}/b/c"/> <au:assertFileDoesntExist file="${output}/b/c"/>
<au:assertFileDoesntExist file="${output}/d"/>
</target> </target>


<target name="testPreserveEmptyOverridesDefault" depends="setUp"> <target name="testPreserveEmptyOverridesDefault" depends="setUp">
@@ -70,6 +74,7 @@
<au:assertFileExists file="${output}/a/foo.txt"/> <au:assertFileExists file="${output}/a/foo.txt"/>
<au:assertFileExists file="${output}/b/baz.txt"/> <au:assertFileExists file="${output}/b/baz.txt"/>
<au:assertFileExists file="${output}/b/c"/> <au:assertFileExists file="${output}/b/c"/>
<au:assertFileDoesntExist file="${output}/d"/>
</target> </target>


<target name="testPreserveEmptyOverrulesIncludeEmpty" depends="setUp"> <target name="testPreserveEmptyOverrulesIncludeEmpty" depends="setUp">
@@ -85,6 +90,7 @@
<au:assertFileExists file="${output}/a/foo.txt"/> <au:assertFileExists file="${output}/a/foo.txt"/>
<au:assertFileExists file="${output}/b/baz.txt"/> <au:assertFileExists file="${output}/b/baz.txt"/>
<au:assertFileDoesntExist file="${output}/b/c"/> <au:assertFileDoesntExist file="${output}/b/c"/>
<au:assertFileExists file="${output}/d"/>
</target> </target>


<target name="testPreserveEmptyAndIncludeEmptyFalse" depends="setUp"> <target name="testPreserveEmptyAndIncludeEmptyFalse" depends="setUp">
@@ -100,6 +106,7 @@
<au:assertFileExists file="${output}/a/foo.txt"/> <au:assertFileExists file="${output}/a/foo.txt"/>
<au:assertFileExists file="${output}/b/baz.txt"/> <au:assertFileExists file="${output}/b/baz.txt"/>
<au:assertFileDoesntExist file="${output}/b/c"/> <au:assertFileDoesntExist file="${output}/b/c"/>
<au:assertFileDoesntExist file="${output}/d"/>
</target> </target>


<target name="testPreserveEmptyAndIncludeEmptyTrue" depends="setUp"> <target name="testPreserveEmptyAndIncludeEmptyTrue" depends="setUp">
@@ -115,6 +122,7 @@
<au:assertFileExists file="${output}/a/foo.txt"/> <au:assertFileExists file="${output}/a/foo.txt"/>
<au:assertFileExists file="${output}/b/baz.txt"/> <au:assertFileExists file="${output}/b/baz.txt"/>
<au:assertFileExists file="${output}/b/c"/> <au:assertFileExists file="${output}/b/c"/>
<au:assertFileExists file="${output}/d"/>
</target> </target>


<target name="testPreserveEmptyDirsWithNonRecursiveExclude" depends="setUp"> <target name="testPreserveEmptyDirsWithNonRecursiveExclude" depends="setUp">
@@ -131,6 +139,7 @@
<au:assertFileExists file="${output}/b"/> <au:assertFileExists file="${output}/b"/>
<au:assertFileDoesntExist file="${output}/b/baz.txt"/> <au:assertFileDoesntExist file="${output}/b/baz.txt"/>
<au:assertFileDoesntExist file="${output}/b/c"/> <au:assertFileDoesntExist file="${output}/b/c"/>
<au:assertFileDoesntExist file="${output}/d"/>
</target> </target>


</project> </project>

Loading…
Cancel
Save