Skip to content

Commit

Permalink
Include truncated layer digest into filename instead of a counter in …
Browse files Browse the repository at this point in the history
…OciRepositoryHandler
  • Loading branch information
SgtSilvio committed May 9, 2024
1 parent ea9fd0b commit 9ce052c
Showing 1 changed file with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ internal class OciRepositoryHandler(
}
}
val fileNamePrefix = "${componentId.name}-${componentId.version}"
val layerDigestToVariantNameAndCounter = HashMap<OciDigest, Pair<String, Int>>()
val layerDigestToVariantName = HashMap<OciDigest, String>()
addArray("variants", variantNameComponentPairs) { (variantName, componentWithDigest) ->
val (component, componentDigest, componentSize) = componentWithDigest
addObject {
Expand All @@ -168,22 +168,20 @@ internal class OciRepositoryHandler(
addString("sha1", Hex.encodeHexString(MessageDigest.getInstance("SHA-1").digest(componentJson)))
addString("md5", Hex.encodeHexString(MessageDigest.getInstance("MD5").digest(componentJson)))
}
var counter = 0
for ((digest, size) in component.collectLayerDigestToSize()) {
addObject {
var layerVariantNameAndCounter = layerDigestToVariantNameAndCounter[digest]
if (layerVariantNameAndCounter == null) {
layerVariantNameAndCounter = Pair(variantName, counter++)
layerDigestToVariantNameAndCounter[digest] = layerVariantNameAndCounter
}
val (layerVariantName, layerCounter) = layerVariantNameAndCounter
val layerName = "$fileNamePrefix-${
createOciLayerClassifier(layerVariantName, layerCounter.toString())
}"
val layerVariantName = layerDigestToVariantName.getOrPut(digest) { variantName }
val algorithm = digest.algorithm.ociPrefix
val encodedHash = digest.encodedHash
val classifier = createOciLayerClassifier(
layerVariantName,
algorithm + '!' + encodedHash.take(5) + ".." + encodedHash.takeLast(5),
)
val layerName = "$fileNamePrefix-$classifier"
addString("name", layerName)
addString("url", "$layerVariantName/$digest/$size/$layerName")
addNumber("size", size)
addString(digest.algorithm.ociPrefix, digest.encodedHash)
addString(algorithm, encodedHash)
}
}
}
Expand Down

0 comments on commit 9ce052c

Please sign in to comment.