Skip to content

Commit

Permalink
fix(workers): Fix the handling of file lists
Browse files Browse the repository at this point in the history
File lists for repository provenances are always created for the full
repositories, ignoring any VCS path. This means that the VCS paths must
be removed from repository provenances before requesting the file lists
from the storage. It also means that file lists must be filtered by the
VCS paths so that no unnecessary entries are added to the created ORT
result.

This is a fixup for e047d5a.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
  • Loading branch information
mnonnenmacher committed Dec 11, 2024
1 parent 38fafcd commit fffd446
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions workers/common/src/main/kotlin/common/OrtRunService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ import org.eclipse.apoapsis.ortserver.model.util.asPresent
import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.insert

import org.ossreviewtoolkit.model.FileList
import org.ossreviewtoolkit.model.OrtResult
import org.ossreviewtoolkit.model.Repository
import org.ossreviewtoolkit.model.ResolvedPackageCurations
import org.ossreviewtoolkit.model.ScanResult as OrtScanResult
import org.ossreviewtoolkit.model.config.PackageConfiguration
import org.ossreviewtoolkit.model.config.RepositoryConfiguration
import org.ossreviewtoolkit.model.config.Resolutions
import org.ossreviewtoolkit.model.utils.getKnownProvenancesWithoutVcsPath
import org.ossreviewtoolkit.scanner.utils.FileListResolver
import org.ossreviewtoolkit.scanner.utils.filterScanResultsByVcsPaths
import org.ossreviewtoolkit.scanner.utils.getVcsPathsForProvenances
Expand Down Expand Up @@ -311,12 +313,19 @@ class OrtRunService(

val filteredOrtScanResults = filterScanResultsByVcsPath(scannerRun?.provenances, scannerRun?.scanResults)

val provenances = scannerRun?.provenances
?.flatMap { it.getProvenances() }
?.mapTo(mutableSetOf()) { it.mapToOrt() }
.orEmpty()
val provenanceResolutionResults = scannerRun?.provenances?.mapTo(mutableSetOf()) { it.mapToOrt() }.orEmpty()

val fileLists = getFileLists(fileListResolver, provenances)
val provenancesWithoutVcsPath = provenanceResolutionResults
.flatMapTo(mutableSetOf()) { it.getKnownProvenancesWithoutVcsPath().values }

val vcsPathsForProvenances = getVcsPathsForProvenances(provenanceResolutionResults)

val fileLists = getFileLists(fileListResolver, provenancesWithoutVcsPath)
.mapNotNullTo(mutableSetOf()) { fileList ->
vcsPathsForProvenances[fileList.provenance]?.let {
fileList.filterByVcsPaths(it)
}
}

val baseResult = ortRun.mapToOrt(
repository = repository,
Expand Down Expand Up @@ -524,3 +533,16 @@ class OrtRunService(
return filterScanResultsByVcsPaths(ortScanResults, vcsPathsForProvenances)
}
}

/**
* Filter the [files][FileList.files] in this [FileList] to only contain files matching the provided [paths].
*/
private fun FileList.filterByVcsPaths(paths: Collection<String>): FileList {
if (paths.any { it.isBlank() }) return this

return copy(
files = files.filterTo(mutableSetOf()) { file ->
paths.any { file.path.startsWith("$it/") }
}
)
}

0 comments on commit fffd446

Please sign in to comment.