Skip to content

Commit cfdad33

Browse files
committed
refactor(ProvenanceBasedFileStorage): Remove RemoteProvenance cast
Using `UnknownProvenance` catch just like in `ProvenanceBasedPostgresStorage`. Signed-off-by: Jens Keim <[email protected]>
1 parent 5c2fd4e commit cfdad33

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

scanner/src/main/kotlin/storages/ProvenanceBasedFileStorage.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ class ProvenanceBasedFileStorage(private val backend: FileStorage) : ProvenanceB
4646
override fun read(provenance: KnownProvenance, scannerMatcher: ScannerMatcher?): List<ScanResult> {
4747
requireEmptyVcsPath(provenance)
4848

49-
val path = storagePath(provenance as RemoteProvenance)
49+
if (provenance !is RemoteProvenance) {
50+
throw ScanStorageException("Scan result must have a known provenance, but it is $provenance.")
51+
}
52+
53+
val path = storagePath(provenance)
5054

5155
return runCatching {
5256
backend.read(path).use { input ->
@@ -81,7 +85,7 @@ class ProvenanceBasedFileStorage(private val backend: FileStorage) : ProvenanceB
8185

8286
requireEmptyVcsPath(provenance)
8387

84-
if (provenance !is KnownProvenance) {
88+
if (provenance !is RemoteProvenance) {
8589
throw ScanStorageException("Scan result must have a known provenance, but it is $provenance.")
8690
}
8791

@@ -95,7 +99,7 @@ class ProvenanceBasedFileStorage(private val backend: FileStorage) : ProvenanceB
9599

96100
val scanResults = existingScanResults + scanResult
97101

98-
val path = storagePath(provenance as RemoteProvenance)
102+
val path = storagePath(provenance)
99103
val yamlBytes = yamlMapper.writeValueAsBytes(scanResults)
100104
val input = ByteArrayInputStream(yamlBytes)
101105

0 commit comments

Comments
 (0)