From 80395a32af64f955249e9ff89feb0bc409e42cea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 14 Feb 2024 22:01:07 +0100 Subject: [PATCH] Fix manifest updates when we match a layer by TOC digest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Either return a compressed digest and compressed size, or an uncompressed digest and an uncompressed size (if we are allowed to change the manifest); if neither is possible, ignore the match and force a layer pull. In almost all cases, a TOC match implies the layer has a TOC digest annotation, i.e. the input manifest is OCI, where the size field is mandatory; so this should not change which layers will be reused - it just changes the returned size value. Signed-off-by: Miloslav Trmač --- storage/storage_dest.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/storage/storage_dest.go b/storage/storage_dest.go index 5783981b4d..038aef09c5 100644 --- a/storage/storage_dest.go +++ b/storage/storage_dest.go @@ -471,12 +471,21 @@ func (s *storageImageDestination) tryReusingBlobAsPending(blobDigest digest.Dige return false, private.ReusedBlob{}, fmt.Errorf(`looking for layers with TOC digest %q: %w`, options.TOCDigest, err) } if len(layers) > 0 { - s.lockProtected.indexToTOCDigest[*options.LayerIndex] = options.TOCDigest - return true, private.ReusedBlob{ - Digest: blobDigest, - Size: layers[0].UncompressedSize, - MatchedByTOCDigest: true, - }, nil + if size != -1 { + s.lockProtected.indexToTOCDigest[*options.LayerIndex] = options.TOCDigest + return true, private.ReusedBlob{ + Digest: blobDigest, + Size: size, + MatchedByTOCDigest: true, + }, nil + } else if options.CanSubstitute && layers[0].UncompressedDigest != "" { + s.lockProtected.indexToTOCDigest[*options.LayerIndex] = options.TOCDigest + return true, private.ReusedBlob{ + Digest: layers[0].UncompressedDigest, + Size: layers[0].UncompressedSize, + MatchedByTOCDigest: true, + }, nil + } } }