Browse Source

removeNotFollowedSymlinks='true' might be deleting too eagerly. PR 53959

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1555490 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 11 years ago
parent
commit
e46fd219c3
3 changed files with 56 additions and 12 deletions
  1. +7
    -0
      WHATSNEW
  2. +15
    -6
      src/main/org/apache/tools/ant/DirectoryScanner.java
  3. +34
    -6
      src/tests/antunit/taskdefs/delete-and-symlinks-test.xml

+ 7
- 0
WHATSNEW View File

@@ -68,6 +68,13 @@ Fixed bugs:
read-only file as expected but also remove the existing file.
Bugzilla Report 53095

* <delete removeNotFollowedSymlinks="true"> would remove symbolic
links to not-included files. It will still delete symlinks to
directories that would have been followed even if they are not
explicitly included. exclude-Patterns can still be used to
preserve symbolic links.
Bugzilla Report 53959

Other changes:
--------------



+ 15
- 6
src/main/org/apache/tools/ant/DirectoryScanner.java View File

@@ -1012,9 +1012,7 @@ public class DirectoryScanner

if (myfile != null && myfile.exists()) {
if (!followSymlinks && currentPath.isSymlink(basedir)) {
if (!isExcluded(currentPath)) {
notFollowedSymlinks.add(myfile.getAbsolutePath());
}
accountForNotFollowedSymlink(currentPath, myfile);
continue;
}
if (myfile.isDirectory()) {
@@ -1226,9 +1224,7 @@ public class DirectoryScanner
File file = new File(dir, newfiles[i]);
(file.isDirectory()
? dirsExcluded : filesExcluded).addElement(name);
if (!isExcluded(name)) {
notFollowedSymlinks.add(file.getAbsolutePath());
}
accountForNotFollowedSymlink(name, file);
} else {
noLinks.add(newfiles[i]);
}
@@ -1329,6 +1325,19 @@ public class DirectoryScanner
}
}

private void accountForNotFollowedSymlink(String name, File file) {
accountForNotFollowedSymlink(new TokenizedPath(name), file);
}

private void accountForNotFollowedSymlink(TokenizedPath name, File file) {
if (!isExcluded(name) &&
(isIncluded(name)
|| (file.isDirectory() && couldHoldIncluded(name)
&& !contentsExcluded(name)))) {
notFollowedSymlinks.add(file.getAbsolutePath());
}
}

private void processIncluded(TokenizedPath path,
File file, Vector<String> inc, Vector<String> exc,
Vector<String> des) {


+ 34
- 6
src/tests/antunit/taskdefs/delete-and-symlinks-test.xml View File

@@ -31,26 +31,54 @@
<symlink action="delete" link="${link}"/>
</target>

<target name="testNotFollowedLink" if="unix">
<target name="setUp" if="unix">
<mkdir dir="${input}/A/B"/>
<mkdir dir="${input}/C"/>
<property name="link" location="${input}/A/B/C"/>
<symlink link="${link}" resource="${input}/C"/>
</target>

<target name="testNotFollowedLink" if="unix" depends="setUp">
<delete>
<fileset dir="${input}" followSymlinks="false"/>
</delete>
<au:assertFileExists file="${input}/A/B/C"/>
</target>

<target name="testRemoveNotFollowedLink" if="unix">
<mkdir dir="${input}/A/B"/>
<mkdir dir="${input}/C"/>
<property name="link" location="${input}/A/B/C"/>
<symlink link="${link}" resource="${input}/C"/>
<target name="testRemoveNotFollowedLink" if="unix" depends="setUp">
<delete removeNotFollowedSymlinks="true">
<fileset dir="${input}/A" followSymlinks="false"/>
</delete>
<au:assertFileDoesntExist file="${input}/A/B/C"/>
<au:assertFileExists file="${input}/C"/>
</target>

<target name="testRemoveNotFollowedLinkHonorsIncludesOnFiles"
depends="setUp" if="unix"
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=53959">
<delete dir="${input}/C"/>
<touch file="${input}/C"/>
<delete removeNotFollowedSymlinks="true">
<fileset dir="${input}/A" followSymlinks="false" includes="**/D"/>
</delete>
<au:assertFileExists file="${input}/A/B/C"/>
</target>

<target name="testRemoveNotFollowedLinkDeletesNotIncludedDirs"
depends="setUp" if="unix"
description="https://issues.apache.org/bugzilla/show_bug.cgi?id=53959">
<delete removeNotFollowedSymlinks="true">
<fileset dir="${input}/A" followSymlinks="false" includes="**/D"/>
</delete>
<au:assertFileDoesntExist file="${input}/A/B/C"/>
<au:assertFileExists file="${input}/C"/>
</target>

<target name="testRemoveNotFollowedLinkHonorsExcludes" if="unix"
depends="setUp">
<delete removeNotFollowedSymlinks="true">
<fileset dir="${input}/A" followSymlinks="false" excludes="**/C/**"/>
</delete>
<au:assertFileExists file="${input}/A/B/C"/>
</target>
</project>

Loading…
Cancel
Save