From a1663c3a00f0df33d0f9be23adf5a4386d7cb555 Mon Sep 17 00:00:00 2001 From: Zadkiel AHARONIAN Date: Mon, 3 Apr 2023 12:57:38 +0200 Subject: [PATCH] fixes --- internal/commands/copy.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/internal/commands/copy.go b/internal/commands/copy.go index 6e534a1..b6c407d 100644 --- a/internal/commands/copy.go +++ b/internal/commands/copy.go @@ -7,6 +7,8 @@ import ( "sync" "time" + "golang.org/x/sync/errgroup" + "github.com/containers/image/v5/copy" dockerv5 "github.com/containers/image/v5/docker" "github.com/containers/image/v5/signature" @@ -88,22 +90,24 @@ func runCopyCommand() error { var sourcesToCopy []manifest.Source for _, source := range sources { - errs.Go(func() error { + source := source + errs.Go(func() error { exists, err := client.ImageExistsAtRemote(errCtx, source.TargetImage()) if err != nil { return fmt.Errorf("image exists at remote: %w", err) } if !exists || viper.GetBool("force") { - m.Lock() + mu.Lock() sourcesToCopy = append(sourcesToCopy, source) - m.Unlock() + mu.Unlock() } + return nil }) } - + if err := errs.Wait(); err != nil { return err } @@ -151,12 +155,12 @@ func runCopyCommand() error { log.Infof("Copying image %s to %s", source.Image(), source.TargetImage()) destRef, err := imageTransport.ParseReference(fmt.Sprintf("//%s", source.TargetImage())) if err != nil { - return fmt.Errorf("Error parsing target image reference: %w", err) + return fmt.Errorf("unable to parse target image reference: %w", err) } srcRef, err := imageTransport.ParseReference(fmt.Sprintf("//%s", source.Image())) if err != nil { - return fmt.Errorf("Error parsing source image reference: %w", err) + return fmt.Errorf("unable to parse source image reference: %w", err) } if _, err := copy.Image(ctx, policyContext, destRef, srcRef, ©Options); err != nil {