Skip to content

Commit

Permalink
fix: export ErrSkipDesc
Browse files Browse the repository at this point in the history
This allows PreCopy to short circuit copying of a descriptor
  • Loading branch information
ktarplee committed Oct 21, 2023
1 parent bd2e97f commit b361757
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import (
// defaultConcurrency is the default value of CopyGraphOptions.Concurrency.
const defaultConcurrency int = 3 // This value is consistent with dockerd and containerd.

// errSkipDesc signals copyNode() to stop processing a descriptor.
var errSkipDesc = errors.New("skip descriptor")
// ErrSkipDesc signal to stop copying a descriptor. When returned from PreCopy the blob must exist in the target.
var ErrSkipDesc = errors.New("skip descriptor")

// DefaultCopyOptions provides the default CopyOptions.
var DefaultCopyOptions CopyOptions = CopyOptions{
Expand Down Expand Up @@ -281,26 +281,17 @@ func doCopyNode(ctx context.Context, src content.ReadOnlyStorage, dst content.St
func copyNode(ctx context.Context, src content.ReadOnlyStorage, dst content.Storage, desc ocispec.Descriptor, opts CopyGraphOptions) error {
if opts.PreCopy != nil {
if err := opts.PreCopy(ctx, desc); err != nil {
if err == errSkipDesc {
if err == ErrSkipDesc {
return nil
}
return err
}
}

// check existence one more time because PreCopy could have Mounted it or copied it with a back channel
exists, err := dst.Exists(ctx, desc)
if err != nil {
if err := doCopyNode(ctx, src, dst, desc); err != nil {
return err
}

if !exists {
if err := doCopyNode(ctx, src, dst, desc); err != nil {
return err
}
}
// TODO otherwise should PostCopy or OnCopySkip be called

if opts.PostCopy != nil {
return opts.PostCopy(ctx, desc)
}
Expand Down Expand Up @@ -382,7 +373,7 @@ func prepareCopy(ctx context.Context, dst Target, dstRef string, proxy *cas.Prox
}
}
// skip the regular copy workflow
return errSkipDesc
return ErrSkipDesc
}
} else {
postCopy := opts.PostCopy
Expand Down

0 comments on commit b361757

Please sign in to comment.