Skip to content

Commit

Permalink
fix(ScanResultsStorage): Correct debug log output about mismatches
Browse files Browse the repository at this point in the history
Previously, the empty `scanResults` were used in log output. Refactor
code to avoid that error.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Sep 27, 2023
1 parent 2282526 commit fd4ed1b
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions scanner/src/main/kotlin/ScanResultsStorage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -154,27 +154,30 @@ abstract class ScanResultsStorage : PackageBasedScanStorage {
if (results.isEmpty()) {
results
} else {
val scanResults = results.toMutableList()
val (matchingProvenance, nonMatchingProvenance) = results.partition { it.provenance.matches(pkg) }

// Only keep scan results whose provenance information matches the package information.
scanResults.retainAll { it.provenance.matches(pkg) }
if (scanResults.isEmpty()) {
if (matchingProvenance.isEmpty()) {
logger.debug {
"No stored scan results found for $pkg. The following entries with non-matching provenance " +
"have been ignored: ${scanResults.map { it.provenance }}"
"have been ignored: ${nonMatchingProvenance.map { it.provenance }}"
}

matchingProvenance
} else {
// Only keep scan results from compatible scanners.
scanResults.retainAll { scannerCriteria.matches(it.scanner) }
if (scanResults.isEmpty()) {
val (matchingCriteria, nonMatchingCriteria) = matchingProvenance.partition {
scannerCriteria.matches(it.scanner)
}

if (matchingCriteria.isEmpty()) {
logger.debug {
"No stored scan results found for $scannerCriteria. The following entries with " +
"incompatible scanners have been ignored: ${scanResults.map { it.scanner }}"
"No stored scan results for '${pkg.id.toCoordinates()}' match $scannerCriteria. The " +
"following entries with non-matching criteria have been ignored: " +
nonMatchingCriteria.map { it.scanner }
}
}
}

scanResults
matchingCriteria
}
}
}

Expand Down

0 comments on commit fd4ed1b

Please sign in to comment.