From 4aff3fd1b61f217974ab6616a63b7c5b25a66e34 Mon Sep 17 00:00:00 2001 From: wangxiaoxuan273 Date: Fri, 19 Aug 2022 03:44:22 +0000 Subject: [PATCH 1/3] feat:print digeest and media type when content is skipped, use sync.Map to ensure printing only once Signed-off-by: wangxiaoxuan273 --- cmd/oras/pull.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/oras/pull.go b/cmd/oras/pull.go index 9217d9497..f83e71baf 100644 --- a/cmd/oras/pull.go +++ b/cmd/oras/pull.go @@ -19,6 +19,7 @@ import ( "context" "fmt" "os" + "sync" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/spf13/cobra" @@ -85,6 +86,7 @@ Example - Pull files with local cache: } func runPull(opts pullOptions) error { + printed := &sync.Map{} repo, err := opts.NewRepository(opts.targetRef, opts.Common) if err != nil { return err @@ -133,6 +135,13 @@ func runPull(opts pullOptions) error { } // Skip s if s is unnamed and has no successors. if len(ss) == 0 { + if _, exists := printed.Load(s.Digest.String()); !exists { + err = display.PrintStatus(s, "Skipped ", opts.Verbose) + if err != nil { + return nil, err + } + printed.Store(s.Digest.String(), true) + } continue } } From 011c539a0fff6d38fce7f7f99031dc0e2ba309ae Mon Sep 17 00:00:00 2001 From: wangxiaoxuan273 Date: Fri, 19 Aug 2022 04:51:28 +0000 Subject: [PATCH 2/3] used loadorstore instead of load and store Signed-off-by: wangxiaoxuan273 --- cmd/oras/pull.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/oras/pull.go b/cmd/oras/pull.go index f83e71baf..d53eb3612 100644 --- a/cmd/oras/pull.go +++ b/cmd/oras/pull.go @@ -135,12 +135,11 @@ func runPull(opts pullOptions) error { } // Skip s if s is unnamed and has no successors. if len(ss) == 0 { - if _, exists := printed.Load(s.Digest.String()); !exists { + if _, loaded := printed.LoadOrStore(s.Digest.String(), true); !loaded { err = display.PrintStatus(s, "Skipped ", opts.Verbose) if err != nil { return nil, err } - printed.Store(s.Digest.String(), true) } continue } From 5562ddb85561f52467f6ca7ee996f99ecfacfe40 Mon Sep 17 00:00:00 2001 From: wangxiaoxuan273 Date: Fri, 19 Aug 2022 05:31:29 +0000 Subject: [PATCH 3/3] formating change Signed-off-by: wangxiaoxuan273 --- cmd/oras/pull.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cmd/oras/pull.go b/cmd/oras/pull.go index d53eb3612..dcaf0dee3 100644 --- a/cmd/oras/pull.go +++ b/cmd/oras/pull.go @@ -86,7 +86,7 @@ Example - Pull files with local cache: } func runPull(opts pullOptions) error { - printed := &sync.Map{} + var printed sync.Map repo, err := opts.NewRepository(opts.targetRef, opts.Common) if err != nil { return err @@ -136,8 +136,7 @@ func runPull(opts pullOptions) error { // Skip s if s is unnamed and has no successors. if len(ss) == 0 { if _, loaded := printed.LoadOrStore(s.Digest.String(), true); !loaded { - err = display.PrintStatus(s, "Skipped ", opts.Verbose) - if err != nil { + if err = display.PrintStatus(s, "Skipped ", opts.Verbose); err != nil { return nil, err } }