Skip to content

Commit

Permalink
refactor(ort-utils)!: Remove the fallback to read uncompressed files
Browse files Browse the repository at this point in the history
Remove the fallback to read uncompressed files from the
`XZCompressedLocalFileStorage`. The fallback was introduced for backward
compatibility with previously uncompressed storage directories, but the
compressed storage is now the default for several years so that the
fallback can be removed.

Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
  • Loading branch information
mnonnenmacher authored and sschuberth committed Sep 3, 2024
1 parent 8e05bcf commit 1e5ae99
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,4 @@ class XZCompressedLocalFileStorageFunTest : StringSpec({
content shouldBe "content"
}
}

"Can read existing uncompressed data" {
storage { storage, directory ->
val file = directory.resolve("existing-file")
file.writeText("content")

val content = storage.read("existing-file").bufferedReader().use(BufferedReader::readText)

content shouldBe "content"
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.ossreviewtoolkit.utils.ort.storage

import java.io.File
import java.io.FileNotFoundException

import org.apache.commons.compress.compressors.xz.XZCompressorInputStream
import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream
Expand All @@ -36,18 +35,7 @@ class XZCompressedLocalFileStorage(
) : LocalFileStorage(directory) {
override fun transformPath(path: String) = "$path.xz"

override fun read(path: String) =
try {
XZCompressorInputStream(super.read(transformPath(path)))
} catch (compressedFileNotFoundException: FileNotFoundException) {
// Fall back to try reading the uncompressed file.
@Suppress("SwallowedException")
try {
super.read(path)
} catch (uncompressedFileNotFoundException: FileNotFoundException) {
throw uncompressedFileNotFoundException.initCause(compressedFileNotFoundException)
}
}
override fun read(path: String) = XZCompressorInputStream(super.read(transformPath(path)))

override fun safeOutputStream(path: String) = XZCompressorOutputStream(super.safeOutputStream(transformPath(path)))
}

0 comments on commit 1e5ae99

Please sign in to comment.