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