github.com/moby/docker@v26.1.3+incompatible/daemon/containerd/store.go (about) 1 package containerd 2 3 import ( 4 "context" 5 6 "github.com/containerd/containerd/content" 7 cerrdefs "github.com/containerd/containerd/errdefs" 8 containerdlabels "github.com/containerd/containerd/labels" 9 "github.com/distribution/reference" 10 "github.com/opencontainers/go-digest" 11 ocispec "github.com/opencontainers/image-spec/specs-go/v1" 12 ) 13 14 // fakeStoreWithSources fakes the existence of the specified content. 15 // Only existence is faked - Info function will include the distribution source label 16 // which makes it possible to perform cross-repo mount. 17 // ReaderAt will still fail with ErrNotFound. 18 type fakeStoreWithSources struct { 19 s content.Store 20 sources map[digest.Digest]distributionSource 21 } 22 23 // wrapWithFakeMountableBlobs wraps the provided content store. 24 func wrapWithFakeMountableBlobs(s content.Store, sources map[digest.Digest]distributionSource) fakeStoreWithSources { 25 return fakeStoreWithSources{ 26 s: s, 27 sources: sources, 28 } 29 } 30 31 func (p fakeStoreWithSources) Delete(ctx context.Context, dgst digest.Digest) error { 32 return p.s.Delete(ctx, dgst) 33 } 34 35 func (p fakeStoreWithSources) Info(ctx context.Context, dgst digest.Digest) (content.Info, error) { 36 info, err := p.s.Info(ctx, dgst) 37 if err != nil { 38 if !cerrdefs.IsNotFound(err) { 39 return info, err 40 } 41 source, ok := p.sources[dgst] 42 if !ok { 43 return info, err 44 } 45 46 key := containerdlabels.LabelDistributionSource + reference.Domain(source.registryRef) 47 value := reference.Path(source.registryRef) 48 return content.Info{ 49 Digest: dgst, 50 Labels: map[string]string{ 51 key: value, 52 }, 53 }, nil 54 } 55 56 return info, nil 57 } 58 59 func (p fakeStoreWithSources) Update(ctx context.Context, info content.Info, fieldpaths ...string) (content.Info, error) { 60 return p.s.Update(ctx, info, fieldpaths...) 61 } 62 63 func (p fakeStoreWithSources) Walk(ctx context.Context, fn content.WalkFunc, filters ...string) error { 64 return p.s.Walk(ctx, fn, filters...) 65 } 66 67 func (p fakeStoreWithSources) ReaderAt(ctx context.Context, desc ocispec.Descriptor) (content.ReaderAt, error) { 68 return p.s.ReaderAt(ctx, desc) 69 } 70 71 func (p fakeStoreWithSources) Abort(ctx context.Context, ref string) error { 72 return p.s.Abort(ctx, ref) 73 } 74 75 func (p fakeStoreWithSources) ListStatuses(ctx context.Context, filters ...string) ([]content.Status, error) { 76 return p.s.ListStatuses(ctx, filters...) 77 } 78 79 func (p fakeStoreWithSources) Status(ctx context.Context, ref string) (content.Status, error) { 80 return p.s.Status(ctx, ref) 81 } 82 83 func (p fakeStoreWithSources) Writer(ctx context.Context, opts ...content.WriterOpt) (content.Writer, error) { 84 return p.s.Writer(ctx, opts...) 85 }