Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rename ErrSkipDesc to SkipNode #643

Merged
merged 4 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 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 descriptor. When returned from PreCopy the blob must exist in the target.
Wwwsylvia marked this conversation as resolved.
Show resolved Hide resolved
// 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,7 +96,10 @@ 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 copying it. It returns an
Wwwsylvia marked this conversation as resolved.
Show resolved Hide resolved
// oras.SkipNode error if a blob already exists in the target, this means
// a blob may has been made available in the target repository by "Mount()"
// or some other technique.
PreCopy func(ctx context.Context, desc ocispec.Descriptor) error
// PostCopy handles the current descriptor after copying it.
PostCopy func(ctx context.Context, desc ocispec.Descriptor) error
Expand Down Expand Up @@ -282,7 +285,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 +377,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
Loading