Skip to content

Commit

Permalink
Reformat CandidateTemplateWithCompression a bit
Browse files Browse the repository at this point in the history
There's not really a benefit to centralizing the "successful return"
code path any more.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
  • Loading branch information
mtrmac committed Jul 27, 2024
1 parent b7e61fe commit 9aa5e2d
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions pkg/blobinfocache/internal/prioritize/prioritize.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,44 @@ func CandidateTemplateWithCompression(v2Options *blobinfocache.CandidateLocation
}
}

var op types.LayerCompression
var algo *compression.Algorithm
switch compressorName {
case blobinfocache.Uncompressed:
op = types.Decompress
algo = nil
return &blobinfocache.BICReplacementCandidate2{
Digest: digest,
CompressionOperation: types.Decompress,
CompressionAlgorithm: nil,
CompressionAnnotations: nil,
}
case blobinfocache.UnknownCompression:
logrus.Debugf("Ignoring BlobInfoCache record of digest %q with unknown compression", digest.String())
return nil // Not allowed with CandidateLocations2
default:
op = types.Compress
algo_, err := compression.AlgorithmByName(compressorName)
algo, err := compression.AlgorithmByName(compressorName)
if err != nil {
logrus.Debugf("Ignoring BlobInfoCache record of digest %q with unrecognized compression %q: %v",
digest.String(), compressorName, err)
return nil // The BICReplacementCandidate2.CompressionAlgorithm field is required
}
algo = &algo_
}
if !manifest.CandidateCompressionMatchesReuseConditions(manifest.ReuseConditions{
PossibleManifestFormats: v2Options.PossibleManifestFormats,
RequiredCompression: v2Options.RequiredCompression,
}, algo) {
requiredCompresssion := "nil"
if v2Options.RequiredCompression != nil {
requiredCompresssion = v2Options.RequiredCompression.Name()

if !manifest.CandidateCompressionMatchesReuseConditions(manifest.ReuseConditions{
PossibleManifestFormats: v2Options.PossibleManifestFormats,
RequiredCompression: v2Options.RequiredCompression,
}, &algo) {
requiredCompresssion := "nil"
if v2Options.RequiredCompression != nil {
requiredCompresssion = v2Options.RequiredCompression.Name()
}
logrus.Debugf("Ignoring BlobInfoCache record of digest %q, compression %q does not match required %s or MIME types %#v",
digest.String(), compressorName, requiredCompresssion, v2Options.PossibleManifestFormats)
return nil
}
logrus.Debugf("Ignoring BlobInfoCache record of digest %q, compression %q does not match required %s or MIME types %#v",
digest.String(), compressorName, requiredCompresssion, v2Options.PossibleManifestFormats)
return nil
}

return &blobinfocache.BICReplacementCandidate2{
Digest: digest,
CompressionOperation: op,
CompressionAlgorithm: algo,
CompressionAnnotations: nil,
return &blobinfocache.BICReplacementCandidate2{
Digest: digest,
CompressionOperation: types.Compress,
CompressionAlgorithm: &algo,
CompressionAnnotations: nil,
}
}
}

Expand Down

0 comments on commit 9aa5e2d

Please sign in to comment.