Skip to content

Commit 3776676

Browse files
fix: rename ErrSkipDesc to SkipNode (#643)
Resolves #634 Signed-off-by: Xiaoxuan Wang <[email protected]>
1 parent 75d200e commit 3776676

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

copy.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ import (
3737
// defaultConcurrency is the default value of CopyGraphOptions.Concurrency.
3838
const defaultConcurrency int = 3 // This value is consistent with dockerd and containerd.
3939

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

4444
// DefaultCopyOptions provides the default CopyOptions.
4545
var DefaultCopyOptions CopyOptions = CopyOptions{
@@ -96,9 +96,11 @@ type CopyGraphOptions struct {
9696
// cached in the memory.
9797
// If less than or equal to 0, a default (currently 4 MiB) is used.
9898
MaxMetadataBytes int64
99-
// PreCopy handles the current descriptor before copying it.
99+
// PreCopy handles the current descriptor before it is copied. PreCopy can
100+
// return a SkipNode to signal that desc should be skipped when it already
101+
// exists in the target.
100102
PreCopy func(ctx context.Context, desc ocispec.Descriptor) error
101-
// PostCopy handles the current descriptor after copying it.
103+
// PostCopy handles the current descriptor after it is copied.
102104
PostCopy func(ctx context.Context, desc ocispec.Descriptor) error
103105
// OnCopySkipped will be called when the sub-DAG rooted by the current node
104106
// is skipped.
@@ -282,7 +284,7 @@ func doCopyNode(ctx context.Context, src content.ReadOnlyStorage, dst content.St
282284
func copyNode(ctx context.Context, src content.ReadOnlyStorage, dst content.Storage, desc ocispec.Descriptor, opts CopyGraphOptions) error {
283285
if opts.PreCopy != nil {
284286
if err := opts.PreCopy(ctx, desc); err != nil {
285-
if err == ErrSkipDesc {
287+
if err == SkipNode {
286288
return nil
287289
}
288290
return err
@@ -374,7 +376,7 @@ func prepareCopy(ctx context.Context, dst Target, dstRef string, proxy *cas.Prox
374376
}
375377
}
376378
// skip the regular copy workflow
377-
return ErrSkipDesc
379+
return SkipNode
378380
}
379381
} else {
380382
postCopy := opts.PostCopy

copy_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,7 @@ func TestCopyGraph_WithOptions(t *testing.T) {
14331433
t.Fatalf("CopyGraph() error = %v, wantErr %v", err, errdef.ErrSizeExceedsLimit)
14341434
}
14351435

1436-
t.Run("ErrSkipDesc", func(t *testing.T) {
1436+
t.Run("SkipNode", func(t *testing.T) {
14371437
// test CopyGraph with PreCopy = 1
14381438
root = descs[6]
14391439
dst := &countingStorage{storage: cas.NewMemory()}
@@ -1450,7 +1450,7 @@ func TestCopyGraph_WithOptions(t *testing.T) {
14501450
if err != nil {
14511451
t.Fatalf("Failed to fetch: %v", err)
14521452
}
1453-
return oras.ErrSkipDesc
1453+
return oras.SkipNode
14541454
}
14551455
return nil
14561456
},
@@ -1467,7 +1467,7 @@ func TestCopyGraph_WithOptions(t *testing.T) {
14671467
}
14681468
// 7 (exists) - 1 (skipped) = 6 pushes expected
14691469
if got, expected := dst.numPush.Load(), int64(6); got != expected {
1470-
// If we get >=7 then ErrSkipDesc did not short circuit the push like it is supposed to do.
1470+
// If we get >=7 then SkipNode did not short circuit the push like it is supposed to do.
14711471
t.Errorf("count(Push()) = %d, want %d", got, expected)
14721472
}
14731473
})

0 commit comments

Comments
 (0)