Skip to content

Commit

Permalink
Do not stop scanning dir hierarchy on first error
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehutch committed Nov 15, 2022
1 parent 9165a0f commit ac1a282
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
7 changes: 4 additions & 3 deletions src/main/java/io/github/classgraph/ClasspathElement.java
Expand Up @@ -171,16 +171,16 @@ int getNumClassfileMatches() {
* the relative path
* @param log
* the log
* @return true if path should be scanned
*/
protected void checkResourcePathAcceptReject(final String relativePath, final LogNode log) {
protected boolean checkResourcePathAcceptReject(final String relativePath, final LogNode log) {
// Accept/reject classpath elements based on file resource paths
if (!scanSpec.classpathElementResourcePathAcceptReject.acceptAndRejectAreEmpty()) {
if (scanSpec.classpathElementResourcePathAcceptReject.isRejected(relativePath)) {
if (log != null) {
log.log("Reached rejected classpath element resource path, stopping scanning: " + relativePath);
}
skipClasspathElement = true;
return;
return false;
}
if (scanSpec.classpathElementResourcePathAcceptReject.isSpecificallyAccepted(relativePath)) {
if (log != null) {
Expand All @@ -189,6 +189,7 @@ protected void checkResourcePathAcceptReject(final String relativePath, final Lo
containsSpecificallyAcceptedClasspathElementResourcePath = true;
}
}
return true;
}

// -------------------------------------------------------------------------------------------------------------
Expand Down
20 changes: 5 additions & 15 deletions src/main/java/io/github/classgraph/ClasspathElementDir.java
Expand Up @@ -312,9 +312,6 @@ Resource getResource(final String relativePath) {
* the log
*/
private void scanPathRecursively(final Path path, final LogNode log) {
if (skipClasspathElement) {
return;
}
// See if this canonical path has been scanned before, so that recursive scanning doesn't get stuck in an
// infinite loop due to symlinks
Path canonicalPath;
Expand Down Expand Up @@ -362,8 +359,7 @@ private void scanPathRecursively(final Path path, final LogNode log) {
}

// Accept/reject classpath elements based on dir resource paths
checkResourcePathAcceptReject(dirRelativePathStr, log);
if (skipClasspathElement) {
if (!checkResourcePathAcceptReject(dirRelativePathStr, log)) {
return;
}

Expand Down Expand Up @@ -396,7 +392,6 @@ private void scanPathRecursively(final Path path, final LogNode log) {
if (log != null) {
log.log("Could not read directory " + path + " : " + e.getMessage());
}
skipClasspathElement = true;
return;
}
Collections.sort(pathsInDir);
Expand All @@ -420,8 +415,7 @@ private void scanPathRecursively(final Path path, final LogNode log) {
}

// Accept/reject classpath elements based on file resource paths
checkResourcePathAcceptReject(subPathRelativeStr, subLog);
if (skipClasspathElement) {
if (!checkResourcePathAcceptReject(subPathRelativeStr, subLog)) {
return;
}

Expand Down Expand Up @@ -467,13 +461,6 @@ private void scanPathRecursively(final Path path, final LogNode log) {
try {
if (Files.isDirectory(subPath)) {
scanPathRecursively(subPath, subLog);
// If a rejected classpath element resource path was found, it will set skipClasspathElement
if (skipClasspathElement) {
if (subLog != null) {
subLog.addElapsedTime();
}
return;
}
}
} catch (final SecurityException e) {
if (subLog != null) {
Expand Down Expand Up @@ -503,6 +490,9 @@ private void scanPathRecursively(final Path path, final LogNode log) {
*/
@Override
void scanPaths(final LogNode log) {
if (!checkResourcePathAcceptReject(classpathEltPath.toString(), log)) {
skipClasspathElement = true;
}
if (skipClasspathElement) {
return;
}
Expand Down
Expand Up @@ -346,9 +346,8 @@ void scanPaths(final LogNode log) {
}

// Accept/reject classpath elements based on file resource paths
checkResourcePathAcceptReject(relativePath, log);
if (skipClasspathElement) {
return;
if (!checkResourcePathAcceptReject(relativePath, log)) {
continue;
}

// Get match status of the parent directory of this resource's relative path (or reuse the last
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/io/github/classgraph/ClasspathElementZip.java
Expand Up @@ -474,6 +474,9 @@ void scanPaths(final LogNode log) {
if (logicalZipFile == null) {
skipClasspathElement = true;
}
if (!checkResourcePathAcceptReject(getZipFilePath(), log)) {
skipClasspathElement = true;
}
if (skipClasspathElement) {
return;
}
Expand Down Expand Up @@ -582,9 +585,8 @@ void scanPaths(final LogNode log) {
}

// Accept/reject classpath elements based on file resource paths
checkResourcePathAcceptReject(relativePath, log);
if (skipClasspathElement) {
return;
if (!checkResourcePathAcceptReject(relativePath, log)) {
continue;
}

// Get match status of the parent directory of this ZipEntry file's relative path (or reuse the last
Expand Down

0 comments on commit ac1a282

Please sign in to comment.