diff --git a/distribution/metadata/metadata.go b/distribution/metadata/metadata.go index 88c859572d..a45d7fa056 100644 --- a/distribution/metadata/metadata.go +++ b/distribution/metadata/metadata.go @@ -29,7 +29,7 @@ type FSMetadataStore struct { // NewFSMetadataStore creates a new filesystem-based metadata store. func NewFSMetadataStore(basePath string) (*FSMetadataStore, error) { - if err := os.MkdirAll(basePath, 0700); err != nil { + if err := os.MkdirAll(basePath, 0o700); err != nil { return nil, err } return &FSMetadataStore{ @@ -57,10 +57,10 @@ func (store *FSMetadataStore) Set(namespace, key string, value []byte) error { defer store.Unlock() path := store.path(namespace, key) - if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil { + if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { return err } - return ioutils.AtomicWriteFile(path, value, 0644) + return ioutils.AtomicWriteFile(path, value, 0o644) } // Delete removes data indexed by namespace and key. The data file named after diff --git a/distribution/pull_v2_test.go b/distribution/pull_v2_test.go index ca23d3b0dd..74d9cff0a9 100644 --- a/distribution/pull_v2_test.go +++ b/distribution/pull_v2_test.go @@ -195,7 +195,7 @@ func TestValidateManifest(t *testing.T) { func TestFormatPlatform(t *testing.T) { var platform ocispec.Platform - var result = formatPlatform(platform) + result := formatPlatform(platform) if strings.HasPrefix(result, "unknown") { t.Fatal("expected formatPlatform to show a known platform") } diff --git a/distribution/pull_v2_windows.go b/distribution/pull_v2_windows.go index f9698a29c0..97eb1b698b 100644 --- a/distribution/pull_v2_windows.go +++ b/distribution/pull_v2_windows.go @@ -12,6 +12,7 @@ import ( "strings" "github.com/Microsoft/hcsshim/osversion" + "github.com/containerd/containerd/log" "github.com/containerd/containerd/platforms" "github.com/docker/distribution" "github.com/docker/distribution/manifest/manifestlist" @@ -19,7 +20,6 @@ import ( "github.com/docker/distribution/registry/client/transport" "github.com/docker/docker/pkg/system" ocispec "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/containerd/containerd/log" ) var _ distribution.Describable = &layerDescriptor{} diff --git a/distribution/push_v2.go b/distribution/push_v2.go index c10efcebd4..e6ea1d6040 100644 --- a/distribution/push_v2.go +++ b/distribution/push_v2.go @@ -688,6 +688,7 @@ func (bla byLikeness) Less(i, j int) bool { bMatch := numOfMatchingPathComponents(bla.arr[j].SourceRepository, bla.pathComponents) return aMatch > bMatch } + func (bla byLikeness) Swap(i, j int) { bla.arr[i], bla.arr[j] = bla.arr[j], bla.arr[i] } diff --git a/distribution/push_v2_test.go b/distribution/push_v2_test.go index 3a683850a4..3abc68222f 100644 --- a/distribution/push_v2_test.go +++ b/distribution/push_v2_test.go @@ -466,24 +466,28 @@ func TestLayerAlreadyExists(t *testing.T) { } } -type mockReferenceStore struct { -} +type mockReferenceStore struct{} func (s *mockReferenceStore) References(id digest.Digest) []reference.Named { return []reference.Named{} } + func (s *mockReferenceStore) ReferencesByName(ref reference.Named) []refstore.Association { return []refstore.Association{} } + func (s *mockReferenceStore) AddTag(ref reference.Named, id digest.Digest, force bool) error { return nil } + func (s *mockReferenceStore) AddDigest(ref reference.Canonical, id digest.Digest, force bool) error { return nil } + func (s *mockReferenceStore) Delete(ref reference.Named) (bool, error) { return true, nil } + func (s *mockReferenceStore) Get(ref reference.Named) (digest.Digest, error) { return "", nil } @@ -641,14 +645,17 @@ func (m *mockRepo) Named() reference.Named { m.t.Fatalf("Named() not implemented") return nil } + func (m *mockRepo) Manifests(ctc context.Context, options ...distribution.ManifestServiceOption) (distribution.ManifestService, error) { m.t.Fatalf("Manifests() not implemented") return nil, nil } + func (m *mockRepo) Tags(ctc context.Context) distribution.TagService { m.t.Fatalf("Tags() not implemented") return nil } + func (m *mockRepo) Blobs(ctx context.Context) distribution.BlobStore { return &mockBlobStore{ repo: m, @@ -671,6 +678,7 @@ func (m *mockBlobStore) Stat(ctx context.Context, dgst digest.Digest) (distribut } return distribution.Descriptor{}, distribution.ErrBlobUnknown } + func (m *mockBlobStore) Get(ctx context.Context, dgst digest.Digest) ([]byte, error) { m.repo.t.Fatal("Get() not implemented") return nil, nil @@ -690,14 +698,17 @@ func (m *mockBlobStore) Create(ctx context.Context, options ...distribution.Blob m.repo.t.Fatal("Create() not implemented") return nil, nil } + func (m *mockBlobStore) Resume(ctx context.Context, id string) (distribution.BlobWriter, error) { m.repo.t.Fatal("Resume() not implemented") return nil, nil } + func (m *mockBlobStore) Delete(ctx context.Context, dgst digest.Digest) error { m.repo.t.Fatal("Delete() not implemented") return nil } + func (m *mockBlobStore) ServeBlob(ctx context.Context, w http.ResponseWriter, r *http.Request, dgst digest.Digest) error { m.repo.t.Fatalf("ServeBlob() not implemented") return nil @@ -713,18 +724,22 @@ var _ metadata.V2MetadataService = &mockV2MetadataService{} func (*mockV2MetadataService) GetMetadata(diffID layer.DiffID) ([]metadata.V2Metadata, error) { return nil, nil } + func (*mockV2MetadataService) GetDiffID(dgst digest.Digest) (layer.DiffID, error) { return "", nil } + func (m *mockV2MetadataService) Add(diffID layer.DiffID, metadata metadata.V2Metadata) error { m.added = append(m.added, metadata) return nil } + func (m *mockV2MetadataService) TagAndAdd(diffID layer.DiffID, hmacKey []byte, meta metadata.V2Metadata) error { meta.HMAC = metadata.ComputeV2MetadataHMAC(hmacKey, &meta) m.Add(diffID, meta) return nil } + func (m *mockV2MetadataService) Remove(metadata metadata.V2Metadata) error { m.removed = append(m.removed, metadata) return nil diff --git a/distribution/xfer/download.go b/distribution/xfer/download.go index 4568f1beb5..1f3f241eaa 100644 --- a/distribution/xfer/download.go +++ b/distribution/xfer/download.go @@ -96,7 +96,6 @@ type DownloadDescriptor interface { // registered layer. This method is called if a cast to DigestRegisterer is // successful. type DigestRegisterer interface { - // TODO existing implementations in distribution and builder-next swallow errors // when registering the diffID. Consider changing the Registered signature // to return the error. diff --git a/distribution/xfer/download_test.go b/distribution/xfer/download_test.go index f45598517d..ca48388977 100644 --- a/distribution/xfer/download_test.go +++ b/distribution/xfer/download_test.go @@ -126,6 +126,7 @@ func (ls *mockLayerStore) Get(chainID layer.ChainID) (layer.Layer, error) { func (ls *mockLayerStore) Release(l layer.Layer) ([]layer.Metadata, error) { return []layer.Metadata{}, nil } + func (ls *mockLayerStore) CreateRWLayer(string, layer.ChainID, *layer.CreateRWLayerOpts) (layer.RWLayer, error) { return nil, errors.New("not implemented") } @@ -137,6 +138,7 @@ func (ls *mockLayerStore) GetRWLayer(string) (layer.RWLayer, error) { func (ls *mockLayerStore) ReleaseRWLayer(layer.RWLayer) ([]layer.Metadata, error) { return nil, errors.New("not implemented") } + func (ls *mockLayerStore) GetMountID(string) (string, error) { return "", errors.New("not implemented") }