Skip to content

Commit

Permalink
fix: address review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Terry Howe <[email protected]>
  • Loading branch information
TerryHowe committed Dec 3, 2024
1 parent d7c7ab8 commit 7692fbc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion cmd/oras/internal/display/status/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion cmd/oras/internal/display/status/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
22 changes: 12 additions & 10 deletions cmd/oras/internal/display/status/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/oras/root/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 7692fbc

Please sign in to comment.