-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(scanner): Revert the merge of read functions in scan storages #8611
Conversation
With this change it is no more possible to obtain scan results by identifiers, without provenance. In particular, this breaks `helper-cli`'s `Create` command which always passes an empty provenance, see [1]. This reverts commit 70b1b86. [1]: https://github.com/oss-review-toolkit/ort/blob/9b34a7b1f21237d01a29e3eb64fa2c767bee120c/helper-cli/src/main/kotlin/commands/packageconfig/CreateCommand.kt#L123 Signed-off-by: Frank Viernau <[email protected]>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8611 +/- ##
============================================
- Coverage 67.97% 67.93% -0.04%
+ Complexity 1005 1003 -2
============================================
Files 244 244
Lines 7844 7869 +25
Branches 876 876
============================================
+ Hits 5332 5346 +14
- Misses 2129 2139 +10
- Partials 383 384 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
* | ||
* Throws a [ScanStorageException] if an error occurs while reading from the storage. | ||
*/ | ||
fun read(pkg: Package, nestedProvenance: NestedProvenance): List<NestedProvenanceScanResult> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this change it is no more possible to obtain scan results by identifiers, without provenance.
I'm having difficulties to understand this reason, because all this commit does is to add back a function to the interface that also takes a NestedProvenance
. So how does getting this function back help to read scan results without provenance?
Or phrased differently, this code in the helper-cli
scanResultsStorage.read(Package.EMPTY.copy(id = packageId)).getOrThrow()
stays the same before and after this change. What magic does it make work, and why was it broken before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code filters by provenance:
override fun readInternal(pkg: Package, scannerMatcher: ScannerMatcher?): Result<List<ScanResult>> =
readForId(pkg.id).map { results -> results.filter { it.provenance.matches(pkg) } }
The code before didn't:
override fun readInternal(pkg: Package): Result<List<ScanResult>> {
val path = storagePath(pkg.id)
return runCatching {
backend.read(path).use { input ->
yamlMapper.readValue<ScanResultContainer>(input).results
}
}.recoverCatching {
// If the file cannot be found it means no scan results have been stored, yet.
if (it is FileNotFoundException) return Result.success(emptyList())
val message = "Could not read scan results for '${pkg.id.toCoordinates()}' from path '$path': " +
it.collectMessages()
logger.info { message }
throw ScanStorageException(message)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me the proper fix would be to start using the PackageProvenanceStorage
to retrieve the resolved provenance instead of reverting this commit (there is readProvenances(id: Identifier): List<PackageProvenanceResolutionResult>
to get all resolved provenances for a package). That would also be less code to maintain than reintroducing this function. Also, I don't like that all package based storages would have to implement that function with the only user being a helper-cli command which is hardcoded to use a local package based storage.
The use case is as follows:
So, the storage involved is not the shared (usually postgtres storage), but a local one which just contains the scan results of one single Would you have an alternative idea which fullfills this requirement @mnonnenmacher? In particular, would it be an option to drop the filtering by provenance again, which has been introduced in your commit? |
I've crafted a minimal invasive solution to fix the issue timely: #8613 |
The provenance resolutions can also be stored in a local file storage, this is the default if no scan storage is configured. So I think the cleanest solution would be that
I would really not like that as for the ORT scanner it is a central concept that scan results have to match not only the id but also the provenance of a package, this is not only the case for scan result storages but for example also for package configurations. |
If I implemented that, my gut feeling is that it would not be a super low effort hing to do.
We had for a long time a central concept which allowed to retrieve scan results by ID from any storage. [1] #7641 |
Alternative solution has been merged: #7641 |
With this change it is no more possible to obtain scan results by identifiers, without provenance. In particular, this breaks
helper-cli
'sCreate
command which always passes an empty provenance, see 1.This reverts commit 70b1b86.