Skip to content

Commit

Permalink
fix: rename ErrSkipDesc to SkipNode (#643)
Browse files Browse the repository at this point in the history
Resolves #634
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
  • Loading branch information
wangxiaoxuan273 authored Nov 21, 2023
1 parent 75d200e commit 3776676
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 8 additions & 6 deletions copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import (
// defaultConcurrency is the default value of CopyGraphOptions.Concurrency.
const defaultConcurrency int = 3 // This value is consistent with dockerd and containerd.

// ErrSkipDesc signals to stop copying a descriptor. When returned from PreCopy the blob must exist in the target.
// SkipNode signals to stop copying a node. When returned from PreCopy the blob must exist in the target.
// This can be used to signal that a blob has been made available in the target repository by "Mount()" or some other technique.
var ErrSkipDesc = errors.New("skip descriptor")
var SkipNode = errors.New("skip node")

// DefaultCopyOptions provides the default CopyOptions.
var DefaultCopyOptions CopyOptions = CopyOptions{
Expand Down Expand Up @@ -96,9 +96,11 @@ type CopyGraphOptions struct {
// cached in the memory.
// If less than or equal to 0, a default (currently 4 MiB) is used.
MaxMetadataBytes int64
// PreCopy handles the current descriptor before copying it.
// PreCopy handles the current descriptor before it is copied. PreCopy can
// return a SkipNode to signal that desc should be skipped when it already
// exists in the target.
PreCopy func(ctx context.Context, desc ocispec.Descriptor) error
// PostCopy handles the current descriptor after copying it.
// PostCopy handles the current descriptor after it is copied.
PostCopy func(ctx context.Context, desc ocispec.Descriptor) error
// OnCopySkipped will be called when the sub-DAG rooted by the current node
// is skipped.
Expand Down Expand Up @@ -282,7 +284,7 @@ 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 == SkipNode {
return nil
}
return err
Expand Down Expand Up @@ -374,7 +376,7 @@ func prepareCopy(ctx context.Context, dst Target, dstRef string, proxy *cas.Prox
}
}
// skip the regular copy workflow
return ErrSkipDesc
return SkipNode
}
} else {
postCopy := opts.PostCopy
Expand Down
6 changes: 3 additions & 3 deletions copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,7 @@ func TestCopyGraph_WithOptions(t *testing.T) {
t.Fatalf("CopyGraph() error = %v, wantErr %v", err, errdef.ErrSizeExceedsLimit)
}

t.Run("ErrSkipDesc", func(t *testing.T) {
t.Run("SkipNode", func(t *testing.T) {
// test CopyGraph with PreCopy = 1
root = descs[6]
dst := &countingStorage{storage: cas.NewMemory()}
Expand All @@ -1450,7 +1450,7 @@ func TestCopyGraph_WithOptions(t *testing.T) {
if err != nil {
t.Fatalf("Failed to fetch: %v", err)
}
return oras.ErrSkipDesc
return oras.SkipNode
}
return nil
},
Expand All @@ -1467,7 +1467,7 @@ func TestCopyGraph_WithOptions(t *testing.T) {
}
// 7 (exists) - 1 (skipped) = 6 pushes expected
if got, expected := dst.numPush.Load(), int64(6); got != expected {
// If we get >=7 then ErrSkipDesc did not short circuit the push like it is supposed to do.
// If we get >=7 then SkipNode did not short circuit the push like it is supposed to do.
t.Errorf("count(Push()) = %d, want %d", got, expected)
}
})
Expand Down

0 comments on commit 3776676

Please sign in to comment.