Skip to content

Commit 92d0f5a

Browse files
committed
[cache] Fix descriptor duplication in getAvailableBlobs
The walkBlob function was called with a function having a side effect: appending a descriptor to a list. However, the function could be called multiple times for the same descriptor (once in `walkBlob` and once in `walkBlobVariantsOnly` in that case) leading to duplicate entries in the final list. Instead of the list, we can use a map to store the descriptors. With the digest as key, it will ensure we don't store duplicates.
1 parent 141a4a6 commit 92d0f5a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

cache/remote.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ func getAvailableBlobs(ctx context.Context, cs content.Store, chain *solver.Remo
112112
if err != nil {
113113
return nil, err
114114
}
115-
var descs []ocispecs.Descriptor
115+
var descs map[digest.Digest]ocispecs.Descriptor
116116
if err := walkBlob(ctx, cs, target, func(desc ocispecs.Descriptor) bool {
117-
descs = append(descs, desc)
117+
// Nothing prevents this function from being called multiple times for the same descriptor.
118+
// Using a map will prevent duplicates in the result.
119+
descs[desc.Digest] = desc
118120
return true
119121
}); err != nil {
120122
bklog.G(ctx).WithError(err).Warn("failed to walk variant blob") // is not a critical error at this moment.

0 commit comments

Comments
 (0)