From 6709bce48042e2a17e0c1373c64d3ee6818a9970 Mon Sep 17 00:00:00 2001 From: Silvio Giebl Date: Wed, 8 Jan 2025 17:45:16 +0100 Subject: [PATCH] Treat all IOExceptions as if the file does not exist --- .../oci/registry/DistributionRegistryStorage.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/io/github/sgtsilvio/oci/registry/DistributionRegistryStorage.kt b/src/main/kotlin/io/github/sgtsilvio/oci/registry/DistributionRegistryStorage.kt index ce425e5..7124f99 100644 --- a/src/main/kotlin/io/github/sgtsilvio/oci/registry/DistributionRegistryStorage.kt +++ b/src/main/kotlin/io/github/sgtsilvio/oci/registry/DistributionRegistryStorage.kt @@ -37,13 +37,12 @@ class DistributionRegistryStorage(private val directory: Path) : OciRegistryStor resolveBlobLinkFile(repositoryName, digest).getLinkedBlobFile() override fun mountBlob(repositoryName: String, digest: OciDigest, fromRepositoryName: String): Boolean { - val fromBlobLinkFile = resolveBlobLinkFile(fromRepositoryName, digest) val blobDigest = try { - fromBlobLinkFile.readText() - } catch (e: NoSuchFileException) { // TODO is this exception guaranteed? use IOException? + resolveBlobLinkFile(fromRepositoryName, digest).readText() + } catch (e: IOException) { return false }.toOciDigest() - if (!resolveBlobFile(digest).exists()) { + if (!resolveBlobFile(blobDigest).exists()) { return false } resolveBlobLinkFile(repositoryName, digest).createParentDirectories() @@ -109,7 +108,7 @@ class DistributionRegistryStorage(private val directory: Path) : OciRegistryStor private fun Path.getLinkedBlobFile(): Path? { val digest = try { readText() - } catch (e: NoSuchFileException) { + } catch (e: IOException) { return null }.toOciDigest() val blobFile = resolveBlobFile(digest) @@ -122,13 +121,12 @@ class DistributionRegistryStorage(private val directory: Path) : OciRegistryStor private fun Path.readLinkedBlob(): ByteArray? { val digest = try { readText() - } catch (e: NoSuchFileException) { + } catch (e: IOException) { return null }.toOciDigest() - val blobFile = resolveBlobFile(digest) return try { - blobFile.readBytes() - } catch (e: NoSuchFileException) { + resolveBlobFile(digest).readBytes() + } catch (e: IOException) { null } }