From 024ea125f598ecdfbba0f5dac3ada0acfdfaf1d0 Mon Sep 17 00:00:00 2001 From: "Kyle M. Tarplee" Date: Fri, 17 Nov 2023 11:06:06 -0500 Subject: [PATCH] added PostCopy call Signed-off-by: Kyle M. Tarplee --- copy.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/copy.go b/copy.go index 8d878a89..79969f7d 100644 --- a/copy.go +++ b/copy.go @@ -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 { @@ -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 } }