Skip to content

Commit

Permalink
fix(helper-cli): Fix broken reading of scan results by identifier
Browse files Browse the repository at this point in the history
The refactoring done in [1] does not just merges functions, but in
addition changes the behavior of the `read()` function to filter the
result by the provenance of the given package. So, [1] obviously broke
the reading of scan results in `helper-cli`'s `CreateCommand`, see also
[2][3].

A better way to fix this might be to migrate the command to use
a scan results by provenance storage together with a package / nested
provenance storage. As this is a bigger effort, fix the regression from
[1] for now in a rather minimal invasive way, which just bypasses the
filtering by provnenance.

[1]: 70b1b86
[2]: https://github.com/oss-review-toolkit/ort/blob/8ed8e2bff913f1d3aafecfb6eb746614f01dfafc/helper-cli/src/main/kotlin/commands/packageconfig/CreateCommand.kt#L123
[3]: https://github.com/oss-review-toolkit/ort/blob/8ed8e2bff913f1d3aafecfb6eb746614f01dfafc/scanner/src/main/kotlin/storages/PackageBasedFileStorage.kt#L75

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed May 3, 2024
1 parent 8ed8e2b commit 9944229
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import org.ossreviewtoolkit.helper.utils.sortPathExcludes
import org.ossreviewtoolkit.helper.utils.write
import org.ossreviewtoolkit.model.ArtifactProvenance
import org.ossreviewtoolkit.model.Identifier
import org.ossreviewtoolkit.model.Package
import org.ossreviewtoolkit.model.RepositoryProvenance
import org.ossreviewtoolkit.model.ScanResult
import org.ossreviewtoolkit.model.config.PackageConfiguration
Expand Down Expand Up @@ -120,7 +119,7 @@ internal class CreateCommand : CliktCommand(
outputDir.safeMkdirs()

val scanResultsStorage = PackageBasedFileStorage(LocalFileStorage(scanResultsStorageDir))
val scanResults = scanResultsStorage.read(Package.EMPTY.copy(id = packageId)).getOrThrow().run {
val scanResults = scanResultsStorage.readForId(id = packageId).getOrThrow().run {

Check warning on line 122 in helper-cli/src/main/kotlin/commands/packageconfig/CreateCommand.kt

View check run for this annotation

Codecov / codecov/patch

helper-cli/src/main/kotlin/commands/packageconfig/CreateCommand.kt#L122

Added line #L122 was not covered by tests
listOfNotNull(
find { it.provenance is RepositoryProvenance },
find { it.provenance is ArtifactProvenance }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PackageBasedFileStorage(
) : AbstractPackageBasedScanStorage() {
override val name = "${javaClass.simpleName} with ${backend.javaClass.simpleName} backend"

private fun readForId(id: Identifier): Result<List<ScanResult>> {
fun readForId(id: Identifier): Result<List<ScanResult>> {
val path = storagePath(id)

return runCatching {
Expand Down

0 comments on commit 9944229

Please sign in to comment.