Skip to content

Commit

Permalink
fix: correctly handle OnCopySkipped (#609)
Browse files Browse the repository at this point in the history
Fix: #552
Signed-off-by: Lixia (Sylvia) Lei <[email protected]>
  • Loading branch information
Wwwsylvia authored and shizhMSFT committed Oct 20, 2023
1 parent eb31910 commit b5e74d8
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit b5e74d8

Please sign in to comment.