diff --git a/copy/copy.go b/copy/copy.go index dce9cc863..c1d410e8e 100644 --- a/copy/copy.go +++ b/copy/copy.go @@ -1065,12 +1065,18 @@ func (ic *imageCopier) copyLayer(ctx context.Context, srcInfo types.BlobInfo, to // Diffs are needed if we are encrypting an image or trying to decrypt an image diffIDIsNeeded := ic.diffIDsAreNeeded && cachedDiffID == "" || toEncrypt || (isOciEncrypted(srcInfo.MediaType) && ic.c.ociDecryptConfig != nil) + srcAlgo := "" + if srcInfo.CompressionAlgorithm != nil { + srcAlgo = srcInfo.CompressionAlgorithm.Name() + } // If we already have the blob, and we don't need to compute the diffID, then we don't need to read it from the source. - if !diffIDIsNeeded { + mustRecompress := srcInfo.CompressionOperation != types.PreserveOriginal || srcAlgo != ic.c.compressionFormat.Name() + if !diffIDIsNeeded && !mustRecompress { reused, blobInfo, err := ic.c.dest.TryReusingBlob(ctx, srcInfo, ic.c.blobInfoCache, ic.canSubstituteBlobs) if err != nil { return types.BlobInfo{}, "", errors.Wrapf(err, "Error trying to reuse blob %s at destination", srcInfo.Digest) } + if reused { logrus.Debugf("Skipping blob %s (already present):", srcInfo.Digest) bar := ic.c.createProgressBar(pool, srcInfo, "blob", "skipped: already exists")