diff --git a/cache/remotecache/v1/chains.go b/cache/remotecache/v1/chains.go index 55b9fbd71..7f80399e5 100644 --- a/cache/remotecache/v1/chains.go +++ b/cache/remotecache/v1/chains.go @@ -116,6 +116,12 @@ func (c *CacheChains) Add(dgst digest.Digest, deps [][]solver.CacheLink, results continue } for l, m := range it.children { + if main.children == nil { + main.children = map[unique.Handle[linkv2]]map[*item]struct{}{} + } + if _, ok := main.children[l]; !ok { + main.children[l] = map[*item]struct{}{} + } for ch := range m { main.children[l][ch] = struct{}{} for i, links := range ch.parents { @@ -126,7 +132,7 @@ func (c *CacheChains) Add(dgst digest.Digest, deps [][]solver.CacheLink, results } newlinks[l] = struct{}{} } - main.parents[i] = newlinks + ch.parents[i] = newlinks } } } @@ -143,7 +149,7 @@ func (c *CacheChains) Add(dgst digest.Digest, deps [][]solver.CacheLink, results r.addResult(rr) } - // make sure that none of the deps are childeren of r + // make sure that none of the deps are children of r allChildren := map[*item]struct{}{} if err := r.walkChildren(func(i *item) error { allChildren[i] = struct{}{} diff --git a/cache/remotecache/v1/utils.go b/cache/remotecache/v1/utils.go index 1c2731544..59eb9e556 100644 --- a/cache/remotecache/v1/utils.go +++ b/cache/remotecache/v1/utils.go @@ -179,6 +179,7 @@ func marshalItem(ctx context.Context, it *item, state *marshalState) error { if _, ok := state.recordsByItem[it]; ok { return nil } + state.recordsByItem[it] = -1 rec := CacheRecord{ Digest: it.dgst, @@ -194,6 +195,9 @@ func marshalItem(ctx context.Context, it *item, state *marshalState) error { if !ok { return errors.Errorf("invalid source record: %v", l.src) } + if idx == -1 { + continue + } rec.Inputs[i] = append(rec.Inputs[i], CacheInput{ Selector: l.selector, LinkIndex: idx,