Browse Source

avoid listing directories who's content is never used

master
Stefan Bodewig 3 years ago
parent
commit
eeacf501dd
2 changed files with 26 additions and 6 deletions
  1. +5
    -0
      WHATSNEW
  2. +21
    -6
      src/main/org/apache/tools/ant/DirectoryScanner.java

+ 5
- 0
WHATSNEW View File

@@ -44,6 +44,11 @@ Other changes:
* <ftp> now supports FTPs. * <ftp> now supports FTPs.
Github Pull Request #170 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 Changes from Ant 1.10.11 TO Ant 1.10.12
======================================= =======================================




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

@@ -1126,12 +1126,16 @@ public class DirectoryScanner
private void processSlowScan(final String[] arr) { private void processSlowScan(final String[] arr) {
for (String element : arr) { for (String element : arr) {
final TokenizedPath path = new TokenizedPath(element); final TokenizedPath path = new TokenizedPath(element);
if (!couldHoldIncluded(path) || contentsExcluded(path)) {
if (!scanDuringFastScan(path)) {
scandir(new File(basedir, element), path, false); 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 * Scan the given directory for files and directories. Found files and
* directories are placed in their respective collections, based on the * directories are placed in their respective collections, based on the
@@ -1236,7 +1240,18 @@ public class DirectoryScanner
final String name = vpath + newFile; final String name = vpath + newFile;
final TokenizedPath newPath = new TokenizedPath(path, newFile); final TokenizedPath newPath = new TokenizedPath(path, newFile);
final File file = new File(dir, 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 (children == null || (children.length == 0 && file.isFile())) {
if (isIncluded(newPath)) { if (isIncluded(newPath)) {
accountForIncludedFile(newPath, file); accountForIncludedFile(newPath, file);
@@ -1263,7 +1278,7 @@ public class DirectoryScanner
} else { } else {
everythingIncluded = false; everythingIncluded = false;
dirsNotIncluded.addElement(name); dirsNotIncluded.addElement(name);
if (fast && couldHoldIncluded(newPath) && !contentsExcluded(newPath)) {
if (fast && scanDuringFastScan(newPath)) {
scandir(file, newPath, fast, children, directoryNamesFollowed); scandir(file, newPath, fast, children, directoryNamesFollowed);
} }
} }
@@ -1298,7 +1313,7 @@ public class DirectoryScanner
private void accountForIncludedDir(final TokenizedPath name, final File file, private void accountForIncludedDir(final TokenizedPath name, final File file,
final boolean fast) { final boolean fast) {
processIncluded(name, file, dirsIncluded, dirsExcluded, dirsDeselected); processIncluded(name, file, dirsIncluded, dirsExcluded, dirsDeselected);
if (fast && couldHoldIncluded(name) && !contentsExcluded(name)) {
if (fast && scanDuringFastScan(name)) {
scandir(file, name, fast); scandir(file, name, fast);
} }
} }
@@ -1308,7 +1323,7 @@ public class DirectoryScanner
final String[] children, final String[] children,
final Deque<String> directoryNamesFollowed) { final Deque<String> directoryNamesFollowed) {
processIncluded(name, file, dirsIncluded, dirsExcluded, dirsDeselected); processIncluded(name, file, dirsIncluded, dirsExcluded, dirsDeselected);
if (fast && couldHoldIncluded(name) && !contentsExcluded(name)) {
if (fast && scanDuringFastScan(name)) {
scandir(file, name, fast, children, directoryNamesFollowed); scandir(file, name, fast, children, directoryNamesFollowed);
} }
} }
@@ -1319,7 +1334,7 @@ public class DirectoryScanner


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


Loading…
Cancel
Save