Skip to content

Commit fd4ed1b

Browse files
committed
fix(ScanResultsStorage): Correct debug log output about mismatches
Previously, the empty `scanResults` were used in log output. Refactor code to avoid that error. Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent 2282526 commit fd4ed1b

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

scanner/src/main/kotlin/ScanResultsStorage.kt

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,27 +154,30 @@ abstract class ScanResultsStorage : PackageBasedScanStorage {
154154
if (results.isEmpty()) {
155155
results
156156
} else {
157-
val scanResults = results.toMutableList()
157+
val (matchingProvenance, nonMatchingProvenance) = results.partition { it.provenance.matches(pkg) }
158158

159-
// Only keep scan results whose provenance information matches the package information.
160-
scanResults.retainAll { it.provenance.matches(pkg) }
161-
if (scanResults.isEmpty()) {
159+
if (matchingProvenance.isEmpty()) {
162160
logger.debug {
163161
"No stored scan results found for $pkg. The following entries with non-matching provenance " +
164-
"have been ignored: ${scanResults.map { it.provenance }}"
162+
"have been ignored: ${nonMatchingProvenance.map { it.provenance }}"
165163
}
164+
165+
matchingProvenance
166166
} else {
167-
// Only keep scan results from compatible scanners.
168-
scanResults.retainAll { scannerCriteria.matches(it.scanner) }
169-
if (scanResults.isEmpty()) {
167+
val (matchingCriteria, nonMatchingCriteria) = matchingProvenance.partition {
168+
scannerCriteria.matches(it.scanner)
169+
}
170+
171+
if (matchingCriteria.isEmpty()) {
170172
logger.debug {
171-
"No stored scan results found for $scannerCriteria. The following entries with " +
172-
"incompatible scanners have been ignored: ${scanResults.map { it.scanner }}"
173+
"No stored scan results for '${pkg.id.toCoordinates()}' match $scannerCriteria. The " +
174+
"following entries with non-matching criteria have been ignored: " +
175+
nonMatchingCriteria.map { it.scanner }
173176
}
174177
}
175-
}
176178

177-
scanResults
179+
matchingCriteria
180+
}
178181
}
179182
}
180183

0 commit comments

Comments
 (0)