Skip to content

Commit

Permalink
resolve comment
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <[email protected]>
  • Loading branch information
qweeah committed Oct 19, 2023
1 parent 26cb0b7 commit d648b94
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions cmd/oras/root/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ func runCopy(ctx context.Context, opts copyOptions) error {
}

func doCopy(ctx context.Context, src oras.ReadOnlyGraphTarget, dst oras.GraphTarget, opts copyOptions) (ocispec.Descriptor, error) {
var tracked track.GraphTarget
var err error
// Prepare copy options
committed := &sync.Map{}
extendedCopyOptions := oras.DefaultExtendedCopyOptions
Expand All @@ -162,15 +160,13 @@ func doCopy(ctx context.Context, src oras.ReadOnlyGraphTarget, dst oras.GraphTar
return successorPrinter(d)
})
}
extendedCopyOptions.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error {
committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle])
if tracked == nil {
return display.PrintStatus(desc, "Skipped", opts.Verbose)
}
return tracked.Prompt(desc, "Exists ", opts.Verbose)
}

if opts.TTY == nil {
// none TTY output
extendedCopyOptions.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error {
committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle])
return display.PrintStatus(desc, "Exists ", opts.Verbose)
}
extendedCopyOptions.PreCopy = func(ctx context.Context, desc ocispec.Descriptor) error {
return display.PrintStatus(desc, "Copying", opts.Verbose)
}
Expand All @@ -183,18 +179,24 @@ func doCopy(ctx context.Context, src oras.ReadOnlyGraphTarget, dst oras.GraphTar
}
} else {
// TTY output
successorPrinter = func(desc ocispec.Descriptor) error {
return tracked.Prompt(desc, "Skipped", opts.Verbose)
}
tracked, err = track.NewTarget(dst, "Copying ", "Copied ", opts.TTY)

tracked, err := track.NewTarget(dst, "Copying ", "Copied ", opts.TTY)
if err != nil {
return ocispec.Descriptor{}, err
}
defer tracked.Close()
dst = tracked
successorPrinter = func(desc ocispec.Descriptor) error {
return tracked.Prompt(desc, "Skipped", opts.Verbose)
}
extendedCopyOptions.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error {
committed.Store(desc.Digest.String(), desc.Annotations[ocispec.AnnotationTitle])
return tracked.Prompt(desc, "Exists ", opts.Verbose)
}
}

var desc ocispec.Descriptor
var err error
rOpts := oras.DefaultResolveOptions
rOpts.TargetPlatform = opts.Platform.Platform
if opts.recursive {
Expand Down

0 comments on commit d648b94

Please sign in to comment.