diff --git a/cmd/oras/internal/display/status/interface.go b/cmd/oras/internal/display/status/interface.go index 8480c60a6..dafcdb408 100644 --- a/cmd/oras/internal/display/status/interface.go +++ b/cmd/oras/internal/display/status/interface.go @@ -63,7 +63,7 @@ type CopyHandler interface { PostCopy(ctx context.Context, desc ocispec.Descriptor) error OnMounted(ctx context.Context, desc ocispec.Descriptor) error StartTracking(gt oras.GraphTarget) (oras.GraphTarget, error) - StopTracking() + StopTracking() error } // ManifestIndexCreateHandler handles status output for manifest index create command. diff --git a/cmd/oras/internal/display/status/text.go b/cmd/oras/internal/display/status/text.go index ef31ea85e..618f93725 100644 --- a/cmd/oras/internal/display/status/text.go +++ b/cmd/oras/internal/display/status/text.go @@ -157,7 +157,8 @@ func (ch *TextCopyHandler) StartTracking(gt oras.GraphTarget) (oras.GraphTarget, } // StopTracking ends the copy tracking for the target. -func (ch *TextCopyHandler) StopTracking() { +func (ch *TextCopyHandler) StopTracking() error { + return nil } // OnCopySkipped is called when an object already exists. diff --git a/cmd/oras/internal/display/status/tty.go b/cmd/oras/internal/display/status/tty.go index f94eae61e..369a33e04 100644 --- a/cmd/oras/internal/display/status/tty.go +++ b/cmd/oras/internal/display/status/tty.go @@ -147,28 +147,30 @@ func (ph *TTYPullHandler) TrackTarget(gt oras.GraphTarget) (oras.GraphTarget, St // TTYCopyHandler handles tty status output for copy events. type TTYCopyHandler struct { tty *os.File - committed *sync.Map + committed sync.Map tracked track.GraphTarget } // NewTTYCopyHandler returns a new handler for copy command. func NewTTYCopyHandler(tty *os.File) CopyHandler { return &TTYCopyHandler{ - tty: tty, - committed: &sync.Map{}, + tty: tty, } } // StartTracking returns a tracked target from a graph target. func (ch *TTYCopyHandler) StartTracking(gt oras.GraphTarget) (oras.GraphTarget, error) { - tracked, err := track.NewTarget(gt, copyPromptCopying, copyPromptCopied, ch.tty) - ch.tracked = tracked - return tracked, err + var err error + ch.tracked, err = track.NewTarget(gt, copyPromptCopying, copyPromptCopied, ch.tty) + if err != nil { + return nil, err + } + return ch.tracked, err } // StopTracking ends the copy tracking for the target. -func (ch *TTYCopyHandler) StopTracking() { - _ = ch.tracked.Close() +func (ch *TTYCopyHandler) StopTracking() error { + return ch.tracked.Close() } // OnCopySkipped is called when an object already exists. @@ -178,14 +180,14 @@ func (ch *TTYCopyHandler) OnCopySkipped(_ context.Context, desc ocispec.Descript } // PreCopy implements PreCopy of CopyHandler. -func (ch *TTYCopyHandler) PreCopy(_ context.Context, _ ocispec.Descriptor) error { +func (ch *TTYCopyHandler) PreCopy(context.Context, ocispec.Descriptor) error { return nil } // PostCopy implements PostCopy of CopyHandler. func (ch *TTYCopyHandler) PostCopy(ctx context.Context, desc ocispec.Descriptor) error { ch.committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle]) - successors, err := graph.FilteredSuccessors(ctx, desc, ch.tracked, DeduplicatedFilter(ch.committed)) + successors, err := graph.FilteredSuccessors(ctx, desc, ch.tracked, DeduplicatedFilter(&ch.committed)) if err != nil { return err } diff --git a/cmd/oras/root/cp.go b/cmd/oras/root/cp.go index 9e984395c..79a194b91 100644 --- a/cmd/oras/root/cp.go +++ b/cmd/oras/root/cp.go @@ -128,9 +128,9 @@ func runCopy(cmd *cobra.Command, opts *copyOptions) error { return err } ctx = registryutil.WithScopeHint(ctx, dst, auth.ActionPull, auth.ActionPush) - copyHandler, handler := display.NewCopyHandler(opts.Printer, opts.TTY, dst) + statusHandler, metadataHandler := display.NewCopyHandler(opts.Printer, opts.TTY, dst) - desc, err := doCopy(ctx, copyHandler, src, dst, opts) + desc, err := doCopy(ctx, statusHandler, src, dst, opts) if err != nil { return err } @@ -144,7 +144,7 @@ func runCopy(cmd *cobra.Command, opts *copyOptions) error { if len(opts.extraRefs) != 0 { tagNOpts := oras.DefaultTagNOptions tagNOpts.Concurrency = opts.concurrency - tagListener := listener.NewTaggedListener(dst, handler.OnTagged) + tagListener := listener.NewTaggedListener(dst, metadataHandler.OnTagged) if _, err = oras.TagN(ctx, tagListener, opts.To.Reference, opts.extraRefs, tagNOpts); err != nil { return err }