From e46fd219c35e1230ed996ade7466b9bc10cea069 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Sun, 5 Jan 2014 12:54:29 +0000 Subject: [PATCH] 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 --- WHATSNEW | 7 ++++ .../apache/tools/ant/DirectoryScanner.java | 21 +++++++--- .../taskdefs/delete-and-symlinks-test.xml | 40 ++++++++++++++++--- 3 files changed, 56 insertions(+), 12 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 887822072..82d1cde4e 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -68,6 +68,13 @@ Fixed bugs: read-only file as expected but also remove the existing file. Bugzilla Report 53095 + * 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: -------------- diff --git a/src/main/org/apache/tools/ant/DirectoryScanner.java b/src/main/org/apache/tools/ant/DirectoryScanner.java index 92d97dec0..9049cc6c5 100644 --- a/src/main/org/apache/tools/ant/DirectoryScanner.java +++ b/src/main/org/apache/tools/ant/DirectoryScanner.java @@ -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 inc, Vector exc, Vector des) { diff --git a/src/tests/antunit/taskdefs/delete-and-symlinks-test.xml b/src/tests/antunit/taskdefs/delete-and-symlinks-test.xml index c3791af13..ac789940f 100644 --- a/src/tests/antunit/taskdefs/delete-and-symlinks-test.xml +++ b/src/tests/antunit/taskdefs/delete-and-symlinks-test.xml @@ -31,26 +31,54 @@ - + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + +