Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aslafy-z committed Apr 3, 2023
1 parent 2c9a437 commit a1663c3
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions internal/commands/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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, &copyOptions); err != nil {
Expand Down

0 comments on commit a1663c3

Please sign in to comment.