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.

Fixes #7366.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Oct 29, 2023
1 parent d9839fb commit d02764f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 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",
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 d02764f

Please sign in to comment.