-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2213 from mtrmac/zstd-blob-reuse-choice
Make blob reuse choices manifest-format-sensitive, and allow conversions when writing to format-agnostic transports
- Loading branch information
Showing
14 changed files
with
112 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,41 @@ | ||
package impl | ||
|
||
import ( | ||
"github.com/containers/image/v5/internal/manifest" | ||
"github.com/containers/image/v5/internal/private" | ||
compression "github.com/containers/image/v5/pkg/compression/types" | ||
"golang.org/x/exp/slices" | ||
) | ||
|
||
// BlobMatchesRequiredCompression validates if compression is required by the caller while selecting a blob, if it is required | ||
// CandidateMatchesTryReusingBlobOptions validates if compression is required by the caller while selecting a blob, if it is required | ||
// then function performs a match against the compression requested by the caller and compression of existing blob | ||
// (which can be nil to represent uncompressed or unknown) | ||
func BlobMatchesRequiredCompression(options private.TryReusingBlobOptions, candidateCompression *compression.Algorithm) bool { | ||
if options.RequiredCompression == nil { | ||
return true // no requirement imposed | ||
func CandidateMatchesTryReusingBlobOptions(options private.TryReusingBlobOptions, candidateCompression *compression.Algorithm) bool { | ||
if options.RequiredCompression != nil { | ||
if options.RequiredCompression.Name() == compression.ZstdChunkedAlgorithmName { | ||
// HACK: Never match when the caller asks for zstd:chunked, because we don’t record the annotations required to use the chunked blobs. | ||
// The caller must re-compress to build those annotations. | ||
return false | ||
} | ||
if candidateCompression == nil || (options.RequiredCompression.Name() != candidateCompression.Name()) { | ||
return false | ||
} | ||
} | ||
if options.RequiredCompression.Name() == compression.ZstdChunkedAlgorithmName { | ||
// HACK: Never match when the caller asks for zstd:chunked, because we don’t record the annotations required to use the chunked blobs. | ||
// The caller must re-compress to build those annotations. | ||
return false | ||
|
||
// For candidateCompression == nil, we can’t tell the difference between “uncompressed” and “unknown”; | ||
// and “uncompressed” is acceptable in all known formats (well, it seems to work in practice for schema1), | ||
// so don’t impose any restrictions if candidateCompression == nil | ||
if options.PossibleManifestFormats != nil && candidateCompression != nil { | ||
if !slices.ContainsFunc(options.PossibleManifestFormats, func(mt string) bool { | ||
return manifest.MIMETypeSupportsCompressionAlgorithm(mt, *candidateCompression) | ||
}) { | ||
return false | ||
} | ||
} | ||
return candidateCompression != nil && (options.RequiredCompression.Name() == candidateCompression.Name()) | ||
|
||
return true | ||
} | ||
|
||
func OriginalBlobMatchesRequiredCompression(opts private.TryReusingBlobOptions) bool { | ||
return BlobMatchesRequiredCompression(opts, opts.OriginalCompression) | ||
func OriginalCandidateMatchesTryReusingBlobOptions(opts private.TryReusingBlobOptions) bool { | ||
return CandidateMatchesTryReusingBlobOptions(opts, opts.OriginalCompression) | ||
} |
Oops, something went wrong.