java-topology/defects/buildkit/patch/buildkit-0001-remotecache-haslink-map.patch

70 lines
2 KiB
Diff

# UNDF: UNDF-2026-000000016
diff --git a/cache/remotecache/v1/cachestorage.go b/cache/remotecache/v1/cachestorage.go
index 7ea9fa1..patched 100644
--- a/cache/remotecache/v1/cachestorage.go
+++ b/cache/remotecache/v1/cachestorage.go
@@ -1,7 +1,6 @@
package cacheimport
import (
"context"
- "slices"
"time"
"github.com/moby/buildkit/session"
@@ -109,7 +108,7 @@ func addItemToStorage(k *cacheKeyStorage, it *item, visited map[*item]*itemWithO
type itemWithOutgoingLinks struct {
*item
- links map[nlink][]string
+ links map[nlink]map[string]struct{}
}
func (cs *cacheKeyStorage) Exists(id string) bool {
@@ -65,7 +64,7 @@ func addItemToStorage(k *cacheKeyStorage, it *item, visited map[*item]*itemWithO
cl := nlink{
input: i,
dgst: it.dgst,
selector: l.selector,
}
- src.links[cl] = append(src.links[cl], id)
+ if src.links[cl] == nil {
+ src.links[cl] = map[string]struct{}{}
+ }
+ src.links[cl][id] = struct{}{}
}
}
@@ -78,7 +78,7 @@ func addItemToStorage(k *cacheKeyStorage, it *item, visited map[*item]*itemWithO
itl := &itemWithOutgoingLinks{
item: it,
- links: map[nlink][]string{},
+ links: map[nlink]map[string]struct{}{},
}
@@ -190,9 +190,9 @@ func (cs *cacheKeyStorage) WalkLinks(id string, link solver.CacheInfoLink, fn fu
l := nlink{
dgst: outputKey(link.Digest, int(link.Output)),
input: int(link.Input),
selector: link.Selector.String(),
}
if it, ok := cs.byID[id]; ok {
- for _, id := range it.links[l] {
+ for id := range it.links[l] {
if err := fn(id); err != nil {
return err
}
@@ -237,11 +237,11 @@ func (cs *cacheKeyStorage) HasLink(id string, link solver.CacheInfoLink, target
l := nlink{
dgst: outputKey(link.Digest, int(link.Output)),
input: int(link.Input),
selector: link.Selector.String(),
}
if it, ok := cs.byID[id]; ok {
- if slices.Contains(it.links[l], target) {
- return true
- }
+ _, found := it.links[l][target]
+ return found
}
return false
}