Skip to content

Commit b5e74d8

Browse files
WwwsylviashizhMSFT
authored andcommitted
fix: correctly handle OnCopySkipped (#609)
Fix: #552 Signed-off-by: Lixia (Sylvia) Lei <lixlei@microsoft.com>
1 parent eb31910 commit b5e74d8

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

copy.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -393,18 +393,26 @@ func prepareCopy(ctx context.Context, dst Target, dstRef string, proxy *cas.Prox
393393

394394
onCopySkipped := opts.OnCopySkipped
395395
opts.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error {
396-
if onCopySkipped != nil {
397-
if err := onCopySkipped(ctx, desc); err != nil {
398-
return err
399-
}
400-
}
401396
if !content.Equal(desc, root) {
397+
if onCopySkipped != nil {
398+
return onCopySkipped(ctx, desc)
399+
}
402400
return nil
403401
}
404-
// enforce tagging when root is skipped
402+
403+
// enforce tagging when the skipped node is root
405404
if refPusher, ok := dst.(registry.ReferencePusher); ok {
405+
// NOTE: refPusher tags the node by copying it with the reference,
406+
// so onCopySkipped shouldn't be invoked in this case
406407
return copyCachedNodeWithReference(ctx, proxy, refPusher, desc, dstRef)
407408
}
409+
410+
// invoke onCopySkipped before tagging
411+
if onCopySkipped != nil {
412+
if err := onCopySkipped(ctx, desc); err != nil {
413+
return err
414+
}
415+
}
408416
return dst.Tag(ctx, root, dstRef)
409417
}
410418

0 commit comments

Comments
 (0)