Skip to content

Commit

Permalink
copy/single: set requiredCompression if compressionFormat is changed
Browse files Browse the repository at this point in the history
Modifies `copy/single` to correctly use the feature from
containers#2023, that is if compression is
changed blob must be resued only if it matches required compression.

Signed-off-by: Aditya R <[email protected]>
  • Loading branch information
flouthoc committed Jul 19, 2023
1 parent ed10acf commit 8ccda26
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions copy/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type imageCopier struct {
canSubstituteBlobs bool
compressionFormat *compressiontypes.Algorithm // Compression algorithm to use, if the user explicitly requested one, or nil.
compressionLevel *int
requireCompressionFormatMatch bool
}

// copySingleImageResult carries data produced by copySingleImage
Expand Down Expand Up @@ -639,12 +640,20 @@ func (ic *imageCopier) copyLayer(ctx context.Context, srcInfo types.BlobInfo, to
// a failure when we eventually try to update the manifest with the digest and MIME type of the reused blob.
// Fixing that will probably require passing more information to TryReusingBlob() than the current version of
// the ImageDestination interface lets us pass in.
var requiredCompression *compressiontypes.Algorithm
var originalCompression *compressiontypes.Algorithm
if ic.requireCompressionFormatMatch {
requiredCompression = ic.compressionFormat
originalCompression = srcInfo.CompressionAlgorithm
}
reused, reusedBlob, err := ic.c.dest.TryReusingBlobWithOptions(ctx, srcInfo, private.TryReusingBlobOptions{
Cache: ic.c.blobInfoCache,
CanSubstitute: canSubstitute,
EmptyLayer: emptyLayer,
LayerIndex: &layerIndex,
SrcRef: srcRef,
Cache: ic.c.blobInfoCache,
CanSubstitute: canSubstitute,
EmptyLayer: emptyLayer,
LayerIndex: &layerIndex,
SrcRef: srcRef,
RequiredCompression: requiredCompression,
OriginalCompression: originalCompression,
})
if err != nil {
return types.BlobInfo{}, "", fmt.Errorf("trying to reuse blob %s at destination: %w", srcInfo.Digest, err)
Expand Down

0 comments on commit 8ccda26

Please sign in to comment.