diff options
author | Stefan Bodewig <bodewig@apache.org> | 2022-05-27 18:37:16 +0200 |
---|---|---|
committer | Stefan Bodewig <bodewig@apache.org> | 2022-05-27 18:37:16 +0200 |
commit | eeacf501dd15327cd300ecd518284e68bb5af4a4 (patch) | |
tree | e8cab73e810eba92d9ea2710c9c2bf1a4b4e84fc | |
parent | 42d25796451b28d8a96786847dfa633e08839fc0 (diff) | |
download | ant-eeacf501dd15327cd300ecd518284e68bb5af4a4.tar.gz |
avoid listing directories who's content is never used
-rw-r--r-- | WHATSNEW | 5 | ||||
-rw-r--r-- | src/main/org/apache/tools/ant/DirectoryScanner.java | 27 |
2 files changed, 26 insertions, 6 deletions
@@ -44,6 +44,11 @@ Other changes: * <ftp> now supports FTPs. Github Pull Request #170 + * DirectoryScanner avoids listing directory contents when it known it + will never use the information retrieved. This may improve + performance in some special cases. + Bugzilla Report 66048 + Changes from Ant 1.10.11 TO Ant 1.10.12 ======================================= diff --git a/src/main/org/apache/tools/ant/DirectoryScanner.java b/src/main/org/apache/tools/ant/DirectoryScanner.java index 045fdbfe5..b7f647999 100644 --- a/src/main/org/apache/tools/ant/DirectoryScanner.java +++ b/src/main/org/apache/tools/ant/DirectoryScanner.java @@ -1126,12 +1126,16 @@ public class DirectoryScanner private void processSlowScan(final String[] arr) { for (String element : arr) { final TokenizedPath path = new TokenizedPath(element); - if (!couldHoldIncluded(path) || contentsExcluded(path)) { + if (!scanDuringFastScan(path)) { scandir(new File(basedir, element), path, false); } } } + private boolean scanDuringFastScan(TokenizedPath path) { + return couldHoldIncluded(path) && !contentsExcluded(path); + } + /** * Scan the given directory for files and directories. Found files and * directories are placed in their respective collections, based on the @@ -1236,7 +1240,18 @@ public class DirectoryScanner final String name = vpath + newFile; final TokenizedPath newPath = new TokenizedPath(path, newFile); final File file = new File(dir, newFile); - final String[] children = file.list(); + final String[] children; + + // don't invoke file.list() if we know we never use the children + if (fast // slow scan scans everything anyway + && file.isDirectory() // otherwise we need list() to know whether this is a directory + && !scanDuringFastScan(newPath) // otherwise we'd invoke scandir + ) { + children = new String[0]; + } else { + children = file.list(); + } + if (children == null || (children.length == 0 && file.isFile())) { if (isIncluded(newPath)) { accountForIncludedFile(newPath, file); @@ -1263,7 +1278,7 @@ public class DirectoryScanner } else { everythingIncluded = false; dirsNotIncluded.addElement(name); - if (fast && couldHoldIncluded(newPath) && !contentsExcluded(newPath)) { + if (fast && scanDuringFastScan(newPath)) { scandir(file, newPath, fast, children, directoryNamesFollowed); } } @@ -1298,7 +1313,7 @@ public class DirectoryScanner private void accountForIncludedDir(final TokenizedPath name, final File file, final boolean fast) { processIncluded(name, file, dirsIncluded, dirsExcluded, dirsDeselected); - if (fast && couldHoldIncluded(name) && !contentsExcluded(name)) { + if (fast && scanDuringFastScan(name)) { scandir(file, name, fast); } } @@ -1308,7 +1323,7 @@ public class DirectoryScanner final String[] children, final Deque<String> directoryNamesFollowed) { processIncluded(name, file, dirsIncluded, dirsExcluded, dirsDeselected); - if (fast && couldHoldIncluded(name) && !contentsExcluded(name)) { + if (fast && scanDuringFastScan(name)) { scandir(file, name, fast, children, directoryNamesFollowed); } } @@ -1319,7 +1334,7 @@ public class DirectoryScanner private void accountForNotFollowedSymlink(final TokenizedPath name, final File file) { if (!isExcluded(name) && (isIncluded(name) - || (file.isDirectory() && couldHoldIncluded(name) && !contentsExcluded(name)))) { + || (file.isDirectory() && scanDuringFastScan(name)))) { notFollowedSymlinks.add(file.getAbsolutePath()); } } |