Author: bodewig
Date: Sun Jan  5 12:54:29 2014
New Revision: 1555490

URL: http://svn.apache.org/r1555490
Log:
removeNotFollowedSymlinks='true' might be deleting too eagerly.  PR 53959

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java
    ant/core/trunk/src/tests/antunit/taskdefs/delete-and-symlinks-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1555490&r1=1555489&r2=1555490&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Sun Jan  5 12:54:29 2014
@@ -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:
 --------------
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java?rev=1555490&r1=1555489&r2=1555490&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java 
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/DirectoryScanner.java Sun Jan  
5 12:54:29 2014
@@ -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) {

Modified: ant/core/trunk/src/tests/antunit/taskdefs/delete-and-symlinks-test.xml
URL: 
http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/delete-and-symlinks-test.xml?rev=1555490&r1=1555489&r2=1555490&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/delete-and-symlinks-test.xml 
(original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/delete-and-symlinks-test.xml Sun 
Jan  5 12:54:29 2014
@@ -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>


Reply via email to