From 5ef94fc81eb7b4a8302044e2f43b69b206590120 Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Mon, 29 Jan 2024 08:40:20 +0000 Subject: [PATCH] bug fix Signed-off-by: Billy Zha --- cmd/oras/internal/display/pull.go | 24 +++++++++++++----------- cmd/oras/root/pull.go | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/cmd/oras/internal/display/pull.go b/cmd/oras/internal/display/pull.go index 41ada5a46..6d20e0fe9 100644 --- a/cmd/oras/internal/display/pull.go +++ b/cmd/oras/internal/display/pull.go @@ -175,7 +175,6 @@ func (ph *PullHandler) printOnce(s ocispec.Descriptor, msg string) error { if ph.trackedGraphTarget != nil { // TTY return ph.trackedGraphTarget.Prompt(s, msg) - } else if ph.needTextOutput { // none TTY return PrintStatus(s, msg, ph.verbose) @@ -225,23 +224,26 @@ func (ph *PullHandler) PostCopy(ctx context.Context, desc ocispec.Descriptor) er name = desc.MediaType } ph.printed.Store(generateContentKey(desc), true) - if ph.trackedGraphTarget != nil { + if ph.needTextOutput { // none TTY, print status log for downloaded return Print(ph.promptDownloaded, ShortDigest(desc), name) } - // TTY return nil } // PostPull is called after pulling. func (ph *PullHandler) PostPull(root ocispec.Descriptor) error { - // suggest oras copy for pulling layers without annotation - if ph.result.layerSkipped { - Print("Skipped pulling layers without file name in", ocispec.AnnotationTitle) - Print("Use 'oras copy", ph.target.RawReference, "--to-oci-layout ' to pull all layers.") - } else { - Print("Pulled", ph.target.AnnotatedReference()) - Print("Digest:", root.Digest) + if ph.template != "" { + return option.WriteMetadata(ph.template, os.Stdout, metadata.NewPull(fmt.Sprintf("%s@%s", ph.target.Path, root.Digest), ph.result.files)) + } else if ph.needTextOutput { + // suggest oras copy for pulling layers without annotation + if ph.result.layerSkipped { + Print("Skipped pulling layers without file name in", ocispec.AnnotationTitle) + Print("Use 'oras copy", ph.target.RawReference, "--to-oci-layout ' to pull all layers.") + } else { + Print("Pulled", ph.target.AnnotatedReference()) + Print("Digest:", root.Digest) + } } - return option.WriteMetadata(ph.template, os.Stdout, metadata.NewPull(fmt.Sprintf("%s@%s", ph.target.Path, root.Digest), ph.result.files)) + return nil } diff --git a/cmd/oras/root/pull.go b/cmd/oras/root/pull.go index 2fb90b4f1..109a0d5fd 100644 --- a/cmd/oras/root/pull.go +++ b/cmd/oras/root/pull.go @@ -149,7 +149,7 @@ func runPull(cmd *cobra.Command, opts *pullOptions) error { } ph := display.NewPullHandler(opts.Template, opts.TTY, tracked, opts.Verbose, opts.IncludeSubject, configPath, configMediaType, opts.Output, &opts.Target) copyOptions.FindSuccessors = ph.FindSuccessors - copyOptions.PreCopy = ph.PostCopy + copyOptions.PreCopy = ph.PreCopy copyOptions.PostCopy = ph.PostCopy root, err := doPull(ctx, src, tracked, copyOptions, opts)