Skip to content

Commit

Permalink
fix(scanner): Catch archiver exceptions
Browse files Browse the repository at this point in the history
Do not only catch exceptions during download, but also when archiving.
Adjust the source of the issue accordingly to not name the "Downloader",
but more generically the "Scanner".

Fixes #7366.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Oct 30, 2023
1 parent e48657f commit 593f6ef
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions scanner/src/main/kotlin/Scanner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.ossreviewtoolkit.scanner

import java.io.File
import java.io.IOException
import java.nio.file.StandardCopyOption
import java.time.Instant

Expand Down Expand Up @@ -714,20 +715,23 @@ class Scanner(

val duration = measureTime {
provenancesWithMissingArchives.forEach { (pkg, nestedProvenance) ->
runCatching {
downloadRecursively(nestedProvenance)
}.onSuccess { dir ->
var dir: File? = null

// runCatching has a bug with smart-cast, see https://youtrack.jetbrains.com/issue/KT-62938.
try {
dir = downloadRecursively(nestedProvenance)
archiver.archive(dir, nestedProvenance.root)
dir.safeDeleteRecursively(force = true)
}.onFailure {
} catch (e: IOException) {
controller.addIssue(
pkg.id,
Issue(
source = "Downloader",
source = "Scanner",
message = "Could not create file archive for " +
"'${pkg.id.toCoordinates()}': ${it.collectMessages()}"
"'${pkg.id.toCoordinates()}': ${e.collectMessages()}"
)
)
} finally {
dir?.safeDeleteRecursively(force = true)
}
}
}
Expand Down

0 comments on commit 593f6ef

Please sign in to comment.