From 29a108af53823307fec2118d9253b85053817d64 Mon Sep 17 00:00:00 2001 From: Martin Nonnenmacher Date: Tue, 3 Sep 2024 15:44:28 +0200 Subject: [PATCH] feat(model): Check if an archive exists before trying to download it 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 --- model/src/main/kotlin/utils/FileArchiver.kt | 5 +++++ scanner/src/main/kotlin/utils/FileListResolver.kt | 1 + 2 files changed, 6 insertions(+) diff --git a/model/src/main/kotlin/utils/FileArchiver.kt b/model/src/main/kotlin/utils/FileArchiver.kt index cdf590928e186..f856ba6a73210 100644 --- a/model/src/main/kotlin/utils/FileArchiver.kt +++ b/model/src/main/kotlin/utils/FileArchiver.kt @@ -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." } diff --git a/scanner/src/main/kotlin/utils/FileListResolver.kt b/scanner/src/main/kotlin/utils/FileListResolver.kt index 6c5b9fc37c4dd..c267207905ca9 100644 --- a/scanner/src/main/kotlin/utils/FileListResolver.kt +++ b/scanner/src/main/kotlin/utils/FileListResolver.kt @@ -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(it) } }