From 2d371a049d743493aa21a9b7181d59a8680445e5 Mon Sep 17 00:00:00 2001 From: "Lixia (Sylvia) Lei" Date: Tue, 26 Sep 2023 18:48:40 +0800 Subject: [PATCH] fix: correctly handle OnCopySkipped (#609) Fix: #552 Signed-off-by: Lixia (Sylvia) Lei --- copy.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/copy.go b/copy.go index e55312dd..ca0f5d6f 100644 --- a/copy.go +++ b/copy.go @@ -393,18 +393,26 @@ func prepareCopy(ctx context.Context, dst Target, dstRef string, proxy *cas.Prox onCopySkipped := opts.OnCopySkipped opts.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error { - if onCopySkipped != nil { - if err := onCopySkipped(ctx, desc); err != nil { - return err - } - } if !content.Equal(desc, root) { + if onCopySkipped != nil { + return onCopySkipped(ctx, desc) + } return nil } - // enforce tagging when root is skipped + + // enforce tagging when the skipped node is root if refPusher, ok := dst.(registry.ReferencePusher); ok { + // NOTE: refPusher tags the node by copying it with the reference, + // so onCopySkipped shouldn't be invoked in this case return copyCachedNodeWithReference(ctx, proxy, refPusher, desc, dstRef) } + + // invoke onCopySkipped before tagging + if onCopySkipped != nil { + if err := onCopySkipped(ctx, desc); err != nil { + return err + } + } return dst.Tag(ctx, root, dstRef) }