diff --git a/cmd/oras/internal/display/status/text.go b/cmd/oras/internal/display/status/text.go index 2ac3a6235..c4277199f 100644 --- a/cmd/oras/internal/display/status/text.go +++ b/cmd/oras/internal/display/status/text.go @@ -17,9 +17,10 @@ package status import ( "context" - "oras.land/oras/internal/graph" "sync" + "oras.land/oras/internal/graph" + ocispec "github.com/opencontainers/image-spec/specs-go/v1" "oras.land/oras-go/v2" "oras.land/oras-go/v2/content" @@ -161,12 +162,12 @@ func (ch *TextCopyHandler) PreCopy(_ context.Context, desc ocispec.Descriptor) e // PostCopy implements PostCopy of CopyHandler. func (ch *TextCopyHandler) 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.fetcher, DeduplicatedFilter(ch.committed)) + deduplicated, err := graph.FilteredSuccessors(ctx, desc, ch.fetcher, DeduplicatedFilter(ch.committed)) if err != nil { return err } - for _, successor := range successors { - if err = ch.printer.PrintStatus(successor, copyPromptExists); err != nil { + for _, successor := range deduplicated { + if err = ch.printer.PrintStatus(successor, copyPromptSkipped); err != nil { return err } } diff --git a/cmd/oras/internal/display/status/text_test.go b/cmd/oras/internal/display/status/text_test.go index 6a1d7c75d..8e68aa76b 100644 --- a/cmd/oras/internal/display/status/text_test.go +++ b/cmd/oras/internal/display/status/text_test.go @@ -19,6 +19,7 @@ import ( "context" "os" "strings" + "sync" "testing" ocispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -68,7 +69,7 @@ func TestTextCopyHandler_OnCopySkipped(t *testing.T) { validatePrinted(t, "Exists 0b442c23c1dd oci-image") } -func TestTextCopyHandler_PostCopy(t *testing.T) { +func TestTextCopyHandler_PostCopy_titled(t *testing.T) { builder.Reset() ch := NewTextCopyHandler(printer, mockFetcher.Fetcher) if ch.PostCopy(ctx, mockFetcher.OciImage) != nil { @@ -80,6 +81,20 @@ func TestTextCopyHandler_PostCopy(t *testing.T) { validatePrinted(t, "Copied 0b442c23c1dd oci-image") } +func TestTextCopyHandler_PostCopy_skipped(t *testing.T) { + builder.Reset() + ch := &TextCopyHandler{ + printer: printer, + fetcher: mockFetcher.Fetcher, + committed: &sync.Map{}, + } + ch.committed.Store(mockFetcher.ImageLayer.Digest.String(), mockFetcher.ImageLayer.Annotations[ocispec.AnnotationTitle]+"bogus") + if err := ch.PostCopy(ctx, mockFetcher.OciImage); err != nil { + t.Error("PostCopy() returns unexpected err:", err) + } + validatePrinted(t, "Skipped f6b87e8e0fe1 layer\nCopied 0b442c23c1dd oci-image") +} + func TestTextCopyHandler_PreCopy(t *testing.T) { builder.Reset() ch := NewTextCopyHandler(printer, mockFetcher.Fetcher)