Skip to content

Commit

Permalink
feat(model): Check if an archive exists before trying to download it
Browse files Browse the repository at this point in the history
Check if an archive exists in the storage before trying to read it in
`FileArchiver.unarchive` and `FileListResolver.resolve`.

This prevents an error message when calling `storage.getData()` and the
data does not exist.

Resolves #7041.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
  • Loading branch information
mnonnenmacher authored and sschuberth committed Sep 3, 2024
1 parent f991e15 commit 29a108a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions model/src/main/kotlin/utils/FileArchiver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ class FileArchiver(
* Unarchive the archive corresponding to [provenance].
*/
fun unarchive(directory: File, provenance: KnownProvenance): Boolean {
if (!storage.hasData(provenance)) {
logger.info { "Could not find archive of directory '$directory'." }
return false
}

val (zipInputStream, readDuration) = measureTimedValue { storage.getData(provenance) }

logger.info { "Read archive of directory '$directory' from storage in $readDuration." }
Expand Down
1 change: 1 addition & 0 deletions scanner/src/main/kotlin/utils/FileListResolver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ private fun ProvenanceFileStorage.putFileList(provenance: KnownProvenance, fileL
}

private fun ProvenanceFileStorage.getFileList(provenance: KnownProvenance): FileList? {
if (!hasData(provenance)) return null
val data = getData(provenance) ?: return null
return data.use { yamlMapper.readValue<FileList>(it) }
}
Expand Down

0 comments on commit 29a108a

Please sign in to comment.