Skip to content

Commit

Permalink
added PostCopy call
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle M. Tarplee <[email protected]>
  • Loading branch information
ktarplee committed Nov 17, 2023
1 parent 59f6b8f commit 024ea12
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ type CopyGraphOptions struct {
// sourceReference is the repository to use for mounting (the mount point).
// mounter is the destination for the mount (a well-known implementation of this is *registry.Repository representing the target).
// onMounted is called (if provided) when the blob is mounted.
// The original PreCopy hook is called only on copy, and there fore not when the blob is mounted.
// The original PreCopy hook is called only on copy, and therefore not when the blob is mounted.
func (opts *CopyGraphOptions) WithMount(sourceRepository string, mounter registry.Mounter, onMounted func(context.Context, ocispec.Descriptor)) {
preCopy := opts.PreCopy
opts.PreCopy = func(ctx context.Context, desc ocispec.Descriptor) error {
Expand Down Expand Up @@ -150,12 +150,22 @@ func (opts *CopyGraphOptions) WithMount(sourceRepository string, mounter registr
return err
}

if !mountFailed && onMounted != nil {
onMounted(ctx, desc)
if !mountFailed {
// mounted
if onMounted != nil {
onMounted(ctx, desc)
}
// signal that the descriptor now exists
return ErrSkipDesc
}

// Mount succeeded or we copied it
// either way we return ErrSkipDesc to signal that the descriptor now exists
// we copied it
if opts.PostCopy != nil {
if err := opts.PostCopy(ctx, desc); err != nil {
return err
}
}
// signal that the descriptor now exists
return ErrSkipDesc
}
}
Expand Down

0 comments on commit 024ea12

Please sign in to comment.