Skip to content

Commit

Permalink
Fix issues moby#1980 and moby#2198
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Giannuzzi <jonathan@giannuzzi.me>
(cherry picked from commit 2c540bd)
  • Loading branch information
jgiannuzzi authored and tonistiigi committed Oct 1, 2021
1 parent c705e46 commit 6316fbc
Showing 1 changed file with 30 additions and 24 deletions.
54 changes: 30 additions & 24 deletions cache/remotecache/v1/cachestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,35 +214,41 @@ func (cs *cacheResultStorage) Save(res solver.Result, createdAt time.Time) (solv
}

func (cs *cacheResultStorage) LoadWithParents(ctx context.Context, res solver.CacheResult) (map[string]solver.Result, error) {
v := cs.byResultID(res.ID)
if v == nil || v.result == nil {
return nil, errors.WithStack(solver.ErrNotFound)
}

m := map[string]solver.Result{}

visited := make(map[*item]struct{})
if err := v.walkAllResults(func(i *item) error {
if i.result == nil {
return nil
}
id, ok := cs.byItem[i]
if !ok {
return nil
}
if isSubRemote(*i.result, *v.result) {
ref, err := cs.w.FromRemote(ctx, i.result)
if err != nil {
return err

ids, ok := cs.byResult[res.ID]
if !ok || len(ids) == 0 {
return nil, errors.WithStack(solver.ErrNotFound)
}

for id := range ids {
v, ok := cs.byID[id]
if ok && v.result != nil {
if err := v.walkAllResults(func(i *item) error {
if i.result == nil {
return nil
}
id, ok := cs.byItem[i]
if !ok {
return nil
}
if isSubRemote(*i.result, *v.result) {
ref, err := cs.w.FromRemote(ctx, i.result)
if err != nil {
return err
}
m[id] = worker.NewWorkerRefResult(ref, cs.w)
}
return nil
}, visited); err != nil {
for _, v := range m {
v.Release(context.TODO())
}
return nil, err
}
m[id] = worker.NewWorkerRefResult(ref, cs.w)
}
return nil
}, visited); err != nil {
for _, v := range m {
v.Release(context.TODO())
}
return nil, err
}

return m, nil
Expand Down

0 comments on commit 6316fbc

Please sign in to comment.