diff --git a/internal/pkg/pkg.go b/internal/pkg/pkg.go index d3816f08..489e34f4 100644 --- a/internal/pkg/pkg.go +++ b/internal/pkg/pkg.go @@ -1922,6 +1922,28 @@ func (c *Cache) tryExtern( return checksum, err } +// cureMany concurrently collects outcome of multiple [Artifact]. +func (c *Cache) cureMany(inputs []Artifact, r map[Artifact]cureRes) error { + var wg sync.WaitGroup + wg.Add(len(inputs)) + res := make([]cureRes, len(inputs)) + errs := make(DependencyCureError, 0, len(inputs)) + var errsMu sync.Mutex + for i, d := range inputs { + pending := pendingArtifactDep{d, &res[i], &errs, &errsMu, &wg} + go pending.cure(c) + } + wg.Wait() + + if len(errs) > 0 { + return &errs + } + for i, p := range res { + r[inputs[i]] = p + } + return nil +} + // cure implements Cure without acquiring a read lock on abortMu. cure must not // be entered during Abort. func (c *Cache) cure(a Artifact, curesExempt bool) ( @@ -2182,25 +2204,9 @@ func (c *Cache) cure(a Artifact, curesExempt bool) ( case FloodArtifact: inputs := a.Inputs() f := FContext{t, make(map[Artifact]cureRes, len(inputs))} - - var wg sync.WaitGroup - wg.Add(len(inputs)) - res := make([]cureRes, len(inputs)) - errs := make(DependencyCureError, 0, len(inputs)) - var errsMu sync.Mutex - for i, d := range inputs { - pending := pendingArtifactDep{d, &res[i], &errs, &errsMu, &wg} - go pending.cure(c) - } - wg.Wait() - - if len(errs) > 0 { - err = &errs + if err = c.cureMany(inputs, f.inputs); err != nil { return } - for i, p := range res { - f.inputs[inputs[i]] = p - } sh := sha512.New384() err = c.encode(sh, a, f.inputs)