Skip to content

Commit

Permalink
copy: skip reusingblob if compression algorithm is different
Browse files Browse the repository at this point in the history
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Nov 26, 2020
1 parent 2e37233 commit e302d91
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions copy/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1065,12 +1065,19 @@ 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 != "" && 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")
Expand Down Expand Up @@ -1482,10 +1489,7 @@ func (c *copier) compressGoroutine(dest *io.PipeWriter, src io.Reader, compressi
return
}
defer func() {
err2 := compressor.Close()
if err == nil {
err = err2
}
err = compressor.Close()
}()

buf := make([]byte, compressionBufferSize)
Expand Down

0 comments on commit e302d91

Please sign in to comment.