Skip to content

Commit

Permalink
Treat all IOExceptions as if the file does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtSilvio committed Jan 8, 2025
1 parent 3836310 commit 6709bce
Showing 1 changed file with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
}
Expand Down

0 comments on commit 6709bce

Please sign in to comment.