Skip to content

Commit dd68802

Browse files
moved the check to doCopyNode and Fetch
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
1 parent 617f44f commit dd68802

File tree

4 files changed

+24
-15
lines changed

4 files changed

+24
-15
lines changed

content.go

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"oras.land/oras-go/v2/content"
2727
"oras.land/oras-go/v2/errdef"
2828
"oras.land/oras-go/v2/internal/cas"
29+
"oras.land/oras-go/v2/internal/descriptor"
2930
"oras.land/oras-go/v2/internal/docker"
3031
"oras.land/oras-go/v2/internal/interfaces"
3132
"oras.land/oras-go/v2/internal/platform"
@@ -273,6 +274,9 @@ func Fetch(ctx context.Context, target ReadOnlyTarget, reference string, opts Fe
273274
}
274275
rc, err := target.Fetch(ctx, desc)
275276
if err != nil {
277+
if errors.Is(err, errdef.ErrNotFound) && descriptor.IsForeignLayer(desc) {
278+
return ocispec.Descriptor{}, nil, fmt.Errorf("the artifact with foreign layer %s is not supported: %w", desc.Digest, err)
279+
}
276280
return ocispec.Descriptor{}, nil, err
277281
}
278282
return desc, rc, nil
@@ -291,6 +295,9 @@ func Fetch(ctx context.Context, target ReadOnlyTarget, reference string, opts Fe
291295
proxy.StopCaching = true
292296
rc, err := proxy.Fetch(ctx, desc)
293297
if err != nil {
298+
if errors.Is(err, errdef.ErrNotFound) && descriptor.IsForeignLayer(desc) {
299+
return ocispec.Descriptor{}, nil, fmt.Errorf("the artifact with foreign layer %s is not supported: %w", desc.Digest, err)
300+
}
294301
return ocispec.Descriptor{}, nil, err
295302
}
296303
return desc, rc, nil

copy.go

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"oras.land/oras-go/v2/content"
2727
"oras.land/oras-go/v2/errdef"
2828
"oras.land/oras-go/v2/internal/cas"
29+
"oras.land/oras-go/v2/internal/descriptor"
2930
"oras.land/oras-go/v2/internal/platform"
3031
"oras.land/oras-go/v2/internal/registryutil"
3132
"oras.land/oras-go/v2/internal/status"
@@ -258,6 +259,9 @@ func copyGraph(ctx context.Context, src content.ReadOnlyStorage, dst content.Sto
258259
func doCopyNode(ctx context.Context, src content.ReadOnlyStorage, dst content.Storage, desc ocispec.Descriptor) error {
259260
rc, err := src.Fetch(ctx, desc)
260261
if err != nil {
262+
if errors.Is(err, errdef.ErrNotFound) && descriptor.IsForeignLayer(desc) {
263+
return fmt.Errorf("the artifact with foreign layer %s is not supported: %w", desc.Digest, err)
264+
}
261265
return err
262266
}
263267
defer rc.Close()

internal/descriptor/descriptor.go

+13
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package descriptor
1818
import (
1919
"github.com/opencontainers/go-digest"
2020
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
21+
"oras.land/oras-go/v2/internal/docker"
2122
)
2223

2324
// Descriptor contains the minimun information to describe the disposition of
@@ -45,3 +46,15 @@ func FromOCI(desc ocispec.Descriptor) Descriptor {
4546
Size: desc.Size,
4647
}
4748
}
49+
50+
func IsForeignLayer(desc ocispec.Descriptor) bool {
51+
switch desc.MediaType {
52+
case ocispec.MediaTypeImageLayerNonDistributable,
53+
ocispec.MediaTypeImageLayerNonDistributableGzip,
54+
ocispec.MediaTypeImageLayerNonDistributableZstd,
55+
docker.MediaTypeForeignLayer:
56+
return true
57+
default:
58+
return false
59+
}
60+
}

registry/remote/repository.go

-15
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import (
3535
"oras.land/oras-go/v2/content"
3636
"oras.land/oras-go/v2/errdef"
3737
"oras.land/oras-go/v2/internal/cas"
38-
"oras.land/oras-go/v2/internal/docker"
3938
"oras.land/oras-go/v2/internal/httputil"
4039
"oras.land/oras-go/v2/internal/ioutil"
4140
"oras.land/oras-go/v2/internal/registryutil"
@@ -615,9 +614,6 @@ type blobStore struct {
615614

616615
// Fetch fetches the content identified by the descriptor.
617616
func (s *blobStore) Fetch(ctx context.Context, target ocispec.Descriptor) (rc io.ReadCloser, err error) {
618-
if isForeignLayer(target) {
619-
return nil, fmt.Errorf("the artifact with foreign layer %s is %w", target.Digest, errdef.ErrUnsupported)
620-
}
621617
ref := s.repo.Reference
622618
ref.Reference = target.Digest.String()
623619
ctx = registryutil.WithScopeHint(ctx, ref, auth.ActionPull)
@@ -1432,14 +1428,3 @@ func generateIndex(manifests []ocispec.Descriptor) (ocispec.Descriptor, []byte,
14321428
indexDesc := content.NewDescriptorFromBytes(index.MediaType, indexJSON)
14331429
return indexDesc, indexJSON, nil
14341430
}
1435-
1436-
func isForeignLayer(desc ocispec.Descriptor) bool {
1437-
switch desc.MediaType {
1438-
case ocispec.MediaTypeImageLayerNonDistributable,
1439-
ocispec.MediaTypeImageLayerNonDistributableGzip,
1440-
ocispec.MediaTypeImageLayerNonDistributableZstd,
1441-
docker.MediaTypeForeignLayer:
1442-
return true
1443-
}
1444-
return false
1445-
}

0 commit comments

Comments
 (0)