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 committed Sep 3, 2024
1 parent e0e8465 commit 3c53ae0
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

Check warning on line 107 in model/src/main/kotlin/utils/FileArchiver.kt

View check run for this annotation

Codecov / codecov/patch

model/src/main/kotlin/utils/FileArchiver.kt#L106-L107

Added lines #L106 - L107 were not covered by tests
}

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 3c53ae0

Please sign in to comment.