From da8db4666b08431e701b044c9077648533d97b7e Mon Sep 17 00:00:00 2001 From: Manish Tomar Date: Mon, 4 Feb 2019 16:01:04 -0800 Subject: [PATCH] Fix gometalint errors Signed-off-by: Manish Tomar --- configuration/configuration.go | 8 ++--- configuration/configuration_test.go | 4 +-- configuration/parser.go | 2 +- health/api/api.go | 2 +- manifest/manifestlist/manifestlist.go | 4 +-- manifest/ocischema/builder.go | 2 +- manifest/ocischema/manifest.go | 2 +- manifest/schema1/manifest.go | 4 +-- manifest/schema1/reference_builder.go | 2 +- manifest/schema2/manifest.go | 2 +- manifests.go | 2 +- notifications/bridge.go | 9 ----- notifications/event_test.go | 9 ++--- notifications/http.go | 3 +- notifications/listener_test.go | 3 +- notifications/sinks.go | 5 --- reference/reference.go | 2 +- registry/api/errcode/errors.go | 6 ++-- registry/api/v2/urls.go | 12 ------- registry/api/v2/urls_test.go | 5 --- .../client/auth/challenge/authchallenge.go | 4 +-- registry/client/repository_test.go | 2 +- registry/handlers/api_test.go | 10 ++---- registry/handlers/app.go | 6 ++-- registry/handlers/blobupload.go | 2 +- registry/handlers/hooks.go | 4 +-- registry/handlers/mail.go | 2 +- registry/proxy/proxyblobstore.go | 4 --- registry/proxy/proxyblobstore_test.go | 12 +------ registry/proxy/proxymanifeststore_test.go | 3 +- registry/proxy/scheduler/scheduler.go | 6 ++-- registry/registry.go | 2 +- registry/storage/blobstore.go | 10 ------ registry/storage/driver/azure/azure.go | 6 ++-- registry/storage/driver/inmemory/mfs.go | 14 -------- registry/storage/driver/s3-aws/s3.go | 36 +++++++++---------- .../storage/driver/s3-aws/s3_v2_signer.go | 6 ---- registry/storage/driver/swift/swift.go | 28 +++++++-------- registry/storage/linkedblobstore_test.go | 5 ++- registry/storage/manifeststore_test.go | 8 ++--- registry/storage/paths.go | 21 +++-------- registry/storage/paths_test.go | 1 - registry/storage/purgeuploads.go | 2 +- registry/storage/purgeuploads_test.go | 4 +-- registry/storage/schema2manifesthandler.go | 5 ++- registry/storage/tagstore.go | 19 ---------- registry/storage/util.go | 22 ------------ 47 files changed, 92 insertions(+), 240 deletions(-) delete mode 100644 registry/storage/util.go diff --git a/configuration/configuration.go b/configuration/configuration.go index 690b8ae3..34884dd2 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -391,7 +391,7 @@ func (loglevel *Loglevel) UnmarshalYAML(unmarshal func(interface{}) error) error switch loglevelString { case "error", "warn", "info", "debug": default: - return fmt.Errorf("Invalid loglevel %s Must be one of [error, warn, info, debug]", loglevelString) + return fmt.Errorf("invalid loglevel %s Must be one of [error, warn, info, debug]", loglevelString) } *loglevel = Loglevel(loglevelString) @@ -466,7 +466,7 @@ func (storage *Storage) UnmarshalYAML(unmarshal func(interface{}) error) error { } if len(types) > 1 { - return fmt.Errorf("Must provide exactly one storage type. Provided: %v", types) + return fmt.Errorf("must provide exactly one storage type. Provided: %v", types) } } *storage = storageMap @@ -668,11 +668,11 @@ func Parse(rd io.Reader) (*Configuration, error) { v0_1.Loglevel = Loglevel("") } if v0_1.Storage.Type() == "" { - return nil, errors.New("No storage configuration provided") + return nil, errors.New("no storage configuration provided") } return (*Configuration)(v0_1), nil } - return nil, fmt.Errorf("Expected *v0_1Configuration, received %#v", c) + return nil, fmt.Errorf("expected *v0_1Configuration, received %#v", c) }, }, }) diff --git a/configuration/configuration_test.go b/configuration/configuration_test.go index d57fbf4f..977d569a 100644 --- a/configuration/configuration_test.go +++ b/configuration/configuration_test.go @@ -542,9 +542,7 @@ func copyConfig(config Configuration) *Configuration { } configCopy.Notifications = Notifications{Endpoints: []Endpoint{}} - for _, v := range config.Notifications.Endpoints { - configCopy.Notifications.Endpoints = append(configCopy.Notifications.Endpoints, v) - } + configCopy.Notifications.Endpoints = append(configCopy.Notifications.Endpoints, config.Notifications.Endpoints...) configCopy.HTTP.Headers = make(http.Header) for k, v := range config.HTTP.Headers { diff --git a/configuration/parser.go b/configuration/parser.go index b46f7326..2bf59d21 100644 --- a/configuration/parser.go +++ b/configuration/parser.go @@ -122,7 +122,7 @@ func (p *Parser) Parse(in []byte, v interface{}) error { parseInfo, ok := p.mapping[versionedStruct.Version] if !ok { - return fmt.Errorf("Unsupported version: %q", versionedStruct.Version) + return fmt.Errorf("unsupported version: %q", versionedStruct.Version) } parseAs := reflect.New(parseInfo.ParseAs) diff --git a/health/api/api.go b/health/api/api.go index 73fcc453..a323a127 100644 --- a/health/api/api.go +++ b/health/api/api.go @@ -14,7 +14,7 @@ var ( // DownHandler registers a manual_http_status that always returns an Error func DownHandler(w http.ResponseWriter, r *http.Request) { if r.Method == "POST" { - updater.Update(errors.New("Manual Check")) + updater.Update(errors.New("manual Check")) } else { w.WriteHeader(http.StatusNotFound) } diff --git a/manifest/manifestlist/manifestlist.go b/manifest/manifestlist/manifestlist.go index f4e915ee..54c8f3c9 100644 --- a/manifest/manifestlist/manifestlist.go +++ b/manifest/manifestlist/manifestlist.go @@ -163,7 +163,7 @@ func FromDescriptorsWithMediaType(descriptors []ManifestDescriptor, mediaType st }, } - m.Manifests = make([]ManifestDescriptor, len(descriptors), len(descriptors)) + m.Manifests = make([]ManifestDescriptor, len(descriptors)) copy(m.Manifests, descriptors) deserialized := DeserializedManifestList{ @@ -177,7 +177,7 @@ func FromDescriptorsWithMediaType(descriptors []ManifestDescriptor, mediaType st // UnmarshalJSON populates a new ManifestList struct from JSON data. func (m *DeserializedManifestList) UnmarshalJSON(b []byte) error { - m.canonical = make([]byte, len(b), len(b)) + m.canonical = make([]byte, len(b)) // store manifest list in canonical copy(m.canonical, b) diff --git a/manifest/ocischema/builder.go b/manifest/ocischema/builder.go index 023a8a0b..d90453bc 100644 --- a/manifest/ocischema/builder.go +++ b/manifest/ocischema/builder.go @@ -48,7 +48,7 @@ func NewManifestBuilder(bs distribution.BlobService, configJSON []byte, annotati // valid media type for oci image manifests currently: "" or "application/vnd.oci.image.manifest.v1+json" func (mb *Builder) SetMediaType(mediaType string) error { if mediaType != "" && mediaType != v1.MediaTypeImageManifest { - return errors.New("Invalid media type for OCI image manifest") + return errors.New("invalid media type for OCI image manifest") } mb.mediaType = mediaType diff --git a/manifest/ocischema/manifest.go b/manifest/ocischema/manifest.go index 09ce78b5..b8c4bab5 100644 --- a/manifest/ocischema/manifest.go +++ b/manifest/ocischema/manifest.go @@ -87,7 +87,7 @@ func FromStruct(m Manifest) (*DeserializedManifest, error) { // UnmarshalJSON populates a new Manifest struct from JSON data. func (m *DeserializedManifest) UnmarshalJSON(b []byte) error { - m.canonical = make([]byte, len(b), len(b)) + m.canonical = make([]byte, len(b)) // store manifest in canonical copy(m.canonical, b) diff --git a/manifest/schema1/manifest.go b/manifest/schema1/manifest.go index 5a06b54b..9fef4dc7 100644 --- a/manifest/schema1/manifest.go +++ b/manifest/schema1/manifest.go @@ -108,7 +108,7 @@ type SignedManifest struct { // UnmarshalJSON populates a new SignedManifest struct from JSON data. func (sm *SignedManifest) UnmarshalJSON(b []byte) error { - sm.all = make([]byte, len(b), len(b)) + sm.all = make([]byte, len(b)) // store manifest and signatures in all copy(sm.all, b) @@ -124,7 +124,7 @@ func (sm *SignedManifest) UnmarshalJSON(b []byte) error { } // sm.Canonical stores the canonical manifest JSON - sm.Canonical = make([]byte, len(bytes), len(bytes)) + sm.Canonical = make([]byte, len(bytes)) copy(sm.Canonical, bytes) // Unmarshal canonical JSON into Manifest object diff --git a/manifest/schema1/reference_builder.go b/manifest/schema1/reference_builder.go index a4f6032c..0f1d386a 100644 --- a/manifest/schema1/reference_builder.go +++ b/manifest/schema1/reference_builder.go @@ -58,7 +58,7 @@ func (mb *referenceManifestBuilder) Build(ctx context.Context) (distribution.Man func (mb *referenceManifestBuilder) AppendReference(d distribution.Describable) error { r, ok := d.(Reference) if !ok { - return fmt.Errorf("Unable to add non-reference type to v1 builder") + return fmt.Errorf("unable to add non-reference type to v1 builder") } // Entries need to be prepended diff --git a/manifest/schema2/manifest.go b/manifest/schema2/manifest.go index ee29438f..41f48029 100644 --- a/manifest/schema2/manifest.go +++ b/manifest/schema2/manifest.go @@ -106,7 +106,7 @@ func FromStruct(m Manifest) (*DeserializedManifest, error) { // UnmarshalJSON populates a new Manifest struct from JSON data. func (m *DeserializedManifest) UnmarshalJSON(b []byte) error { - m.canonical = make([]byte, len(b), len(b)) + m.canonical = make([]byte, len(b)) // store manifest in canonical copy(m.canonical, b) diff --git a/manifests.go b/manifests.go index 1816baea..8f84a220 100644 --- a/manifests.go +++ b/manifests.go @@ -87,7 +87,7 @@ func ManifestMediaTypes() (mediaTypes []string) { // UnmarshalFunc implements manifest unmarshalling a given MediaType type UnmarshalFunc func([]byte) (Manifest, Descriptor, error) -var mappings = make(map[string]UnmarshalFunc, 0) +var mappings = make(map[string]UnmarshalFunc) // UnmarshalManifest looks up manifest unmarshal functions based on // MediaType diff --git a/notifications/bridge.go b/notifications/bridge.go index eb9af41a..86af43f3 100644 --- a/notifications/bridge.go +++ b/notifications/bridge.go @@ -125,15 +125,6 @@ func (b *bridge) RepoDeleted(repo reference.Named) error { return b.sink.Write(*event) } -func (b *bridge) createManifestEventAndWrite(action string, repo reference.Named, sm distribution.Manifest) error { - manifestEvent, err := b.createManifestEvent(action, repo, sm) - if err != nil { - return err - } - - return b.sink.Write(*manifestEvent) -} - func (b *bridge) createManifestDeleteEventAndWrite(action string, repo reference.Named, dgst digest.Digest) error { event := b.createEvent(action) event.Target.Repository = repo.Name() diff --git a/notifications/event_test.go b/notifications/event_test.go index 0981a7ad..2dddf944 100644 --- a/notifications/event_test.go +++ b/notifications/event_test.go @@ -114,8 +114,7 @@ func TestEventEnvelopeJSONFormat(t *testing.T) { prototype.Request.UserAgent = "test/0.1" prototype.Source.Addr = "hostname.local:port" - var manifestPush Event - manifestPush = prototype + var manifestPush = prototype manifestPush.ID = "asdf-asdf-asdf-asdf-0" manifestPush.Target.Digest = "sha256:0123456789abcdef0" manifestPush.Target.Length = 1 @@ -124,8 +123,7 @@ func TestEventEnvelopeJSONFormat(t *testing.T) { manifestPush.Target.Repository = "library/test" manifestPush.Target.URL = "http://example.com/v2/library/test/manifests/latest" - var layerPush0 Event - layerPush0 = prototype + var layerPush0 = prototype layerPush0.ID = "asdf-asdf-asdf-asdf-1" layerPush0.Target.Digest = "sha256:3b3692957d439ac1928219a83fac91e7bf96c153725526874673ae1f2023f8d5" layerPush0.Target.Length = 2 @@ -134,8 +132,7 @@ func TestEventEnvelopeJSONFormat(t *testing.T) { layerPush0.Target.Repository = "library/test" layerPush0.Target.URL = "http://example.com/v2/library/test/manifests/latest" - var layerPush1 Event - layerPush1 = prototype + var layerPush1 = prototype layerPush1.ID = "asdf-asdf-asdf-asdf-2" layerPush1.Target.Digest = "sha256:3b3692957d439ac1928219a83fac91e7bf96c153725526874673ae1f2023f8d6" layerPush1.Target.Length = 3 diff --git a/notifications/http.go b/notifications/http.go index 15751619..46f47af2 100644 --- a/notifications/http.go +++ b/notifications/http.go @@ -133,8 +133,7 @@ type headerRoundTripper struct { } func (hrt *headerRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { - var nreq http.Request - nreq = *req + var nreq = *req nreq.Header = make(http.Header) merge := func(headers http.Header) { diff --git a/notifications/listener_test.go b/notifications/listener_test.go index ff49fd00..dee4dac5 100644 --- a/notifications/listener_test.go +++ b/notifications/listener_test.go @@ -136,11 +136,10 @@ func checkExerciseRepository(t *testing.T, repository distribution.Repository, r var blobDigests []digest.Digest blobs := repository.Blobs(ctx) for i := 0; i < 2; i++ { - rs, ds, err := testutil.CreateRandomTarFile() + rs, dgst, err := testutil.CreateRandomTarFile() if err != nil { t.Fatalf("error creating test layer: %v", err) } - dgst := digest.Digest(ds) blobDigests = append(blobDigests, dgst) wr, err := blobs.Create(ctx) diff --git a/notifications/sinks.go b/notifications/sinks.go index 14b692a3..816f75d7 100644 --- a/notifications/sinks.go +++ b/notifications/sinks.go @@ -284,11 +284,6 @@ type retryingSink struct { } } -type retryingSinkListener interface { - active(events ...Event) - retry(events ...Event) -} - // TODO(stevvooe): We are using circuit break here, which actually doesn't // make a whole lot of sense for this use case, since we always retry. Move // this to use bounded exponential backoff. diff --git a/reference/reference.go b/reference/reference.go index 2f66cca8..8c0c23b2 100644 --- a/reference/reference.go +++ b/reference/reference.go @@ -205,7 +205,7 @@ func Parse(s string) (Reference, error) { var repo repository nameMatch := anchoredNameRegexp.FindStringSubmatch(matches[1]) - if nameMatch != nil && len(nameMatch) == 3 { + if len(nameMatch) == 3 { repo.domain = nameMatch[1] repo.path = nameMatch[2] } else { diff --git a/registry/api/errcode/errors.go b/registry/api/errcode/errors.go index 6d9bb4b6..4c35b879 100644 --- a/registry/api/errcode/errors.go +++ b/registry/api/errcode/errors.go @@ -207,11 +207,11 @@ func (errs Errors) MarshalJSON() ([]byte, error) { for _, daErr := range errs { var err Error - switch daErr.(type) { + switch daErr := daErr.(type) { case ErrorCode: - err = daErr.(ErrorCode).WithDetail(nil) + err = daErr.WithDetail(nil) case Error: - err = daErr.(Error) + err = daErr default: err = ErrorCodeUnknown.WithDetail(daErr) diff --git a/registry/api/v2/urls.go b/registry/api/v2/urls.go index 1337bdb1..3c3ec989 100644 --- a/registry/api/v2/urls.go +++ b/registry/api/v2/urls.go @@ -252,15 +252,3 @@ func appendValuesURL(u *url.URL, values ...url.Values) *url.URL { u.RawQuery = merged.Encode() return u } - -// appendValues appends the parameters to the url. Panics if the string is not -// a url. -func appendValues(u string, values ...url.Values) string { - up, err := url.Parse(u) - - if err != nil { - panic(err) // should never happen - } - - return appendValuesURL(up, values...).String() -} diff --git a/registry/api/v2/urls_test.go b/registry/api/v2/urls_test.go index 4f854b23..fbf9d0d4 100644 --- a/registry/api/v2/urls_test.go +++ b/registry/api/v2/urls_test.go @@ -182,11 +182,6 @@ func TestURLBuilderWithPrefix(t *testing.T) { doTest(false) } -type builderFromRequestTestCase struct { - request *http.Request - base string -} - func TestBuilderFromRequest(t *testing.T) { u, err := url.Parse("http://example.com") if err != nil { diff --git a/registry/client/auth/challenge/authchallenge.go b/registry/client/auth/challenge/authchallenge.go index 6e3f1ccc..fe238210 100644 --- a/registry/client/auth/challenge/authchallenge.go +++ b/registry/client/auth/challenge/authchallenge.go @@ -117,8 +117,8 @@ func init() { var t octetType isCtl := c <= 31 || c == 127 isChar := 0 <= c && c <= 127 - isSeparator := strings.IndexRune(" \t\"(),/:;<=>?@[]\\{}", rune(c)) >= 0 - if strings.IndexRune(" \t\r\n", rune(c)) >= 0 { + isSeparator := strings.ContainsRune(" \t\"(),/:;<=>?@[]\\{}", rune(c)) + if strings.ContainsRune(" \t\r\n", rune(c)) { t |= isSpace } if isChar && !isCtl && !isSeparator { diff --git a/registry/client/repository_test.go b/registry/client/repository_test.go index 88e7e4b5..53b53cce 100644 --- a/registry/client/repository_test.go +++ b/registry/client/repository_test.go @@ -152,7 +152,7 @@ func TestBlobFetch(t *testing.T) { if err != nil { t.Fatal(err) } - if bytes.Compare(b, b1) != 0 { + if !bytes.Equal(b, b1) { t.Fatalf("Wrong bytes values fetched: [%d]byte != [%d]byte", len(b), len(b1)) } diff --git a/registry/handlers/api_test.go b/registry/handlers/api_test.go index 2544efba..092f7be2 100644 --- a/registry/handlers/api_test.go +++ b/registry/handlers/api_test.go @@ -959,7 +959,6 @@ func testManifestWithStorageError(t *testing.T, env *testEnv, imageName referenc defer resp.Body.Close() checkResponse(t, "getting non-existent manifest", resp, expectedStatusCode) checkBodyHasErrorCodes(t, "getting non-existent manifest", resp, expectedErrorCode) - return } func testManifestAPISchema1(t *testing.T, env *testEnv, imageName reference.Named) manifestArgs { @@ -1066,12 +1065,11 @@ func testManifestAPISchema1(t *testing.T, env *testEnv, imageName reference.Name expectedLayers := make(map[digest.Digest]io.ReadSeeker) for i := range unsignedManifest.FSLayers { - rs, dgstStr, err := testutil.CreateRandomTarFile() + rs, dgst, err := testutil.CreateRandomTarFile() if err != nil { t.Fatalf("error creating random layer %d: %v", i, err) } - dgst := digest.Digest(dgstStr) expectedLayers[dgst] = rs unsignedManifest.FSLayers[i].BlobSum = dgst @@ -1405,12 +1403,11 @@ func testManifestAPISchema2(t *testing.T, env *testEnv, imageName reference.Name expectedLayers := make(map[digest.Digest]io.ReadSeeker) for i := range manifest.Layers { - rs, dgstStr, err := testutil.CreateRandomTarFile() + rs, dgst, err := testutil.CreateRandomTarFile() if err != nil { t.Fatalf("error creating random layer %d: %v", i, err) } - dgst := digest.Digest(dgstStr) expectedLayers[dgst] = rs manifest.Layers[i].Digest = dgst @@ -2432,11 +2429,10 @@ func createRepository(env *testEnv, t *testing.T, imageName string, tag string) expectedLayers := make(map[digest.Digest]io.ReadSeeker) for i := range unsignedManifest.FSLayers { - rs, dgstStr, err := testutil.CreateRandomTarFile() + rs, dgst, err := testutil.CreateRandomTarFile() if err != nil { t.Fatalf("error creating random layer %d: %v", i, err) } - dgst := digest.Digest(dgstStr) expectedLayers[dgst] = rs unsignedManifest.FSLayers[i].BlobSum = dgst diff --git a/registry/handlers/app.go b/registry/handlers/app.go index 978851bb..5980753b 100644 --- a/registry/handlers/app.go +++ b/registry/handlers/app.go @@ -753,20 +753,18 @@ func (app *App) logError(ctx context.Context, errors errcode.Errors) { for _, e1 := range errors { var c context.Context - switch e1.(type) { + switch e := e1.(type) { case errcode.Error: - e, _ := e1.(errcode.Error) c = context.WithValue(ctx, errCodeKey{}, e.Code) c = context.WithValue(c, errMessageKey{}, e.Message) c = context.WithValue(c, errDetailKey{}, e.Detail) case errcode.ErrorCode: - e, _ := e1.(errcode.ErrorCode) c = context.WithValue(ctx, errCodeKey{}, e) c = context.WithValue(c, errMessageKey{}, e.Message()) default: // just normal go 'error' c = context.WithValue(ctx, errCodeKey{}, errcode.ErrorCodeUnknown) - c = context.WithValue(c, errMessageKey{}, e1.Error()) + c = context.WithValue(c, errMessageKey{}, e.Error()) } c = dcontext.WithLogger(c, dcontext.GetLogger(c, diff --git a/registry/handlers/blobupload.go b/registry/handlers/blobupload.go index 49ab1aaa..b6bfe302 100644 --- a/registry/handlers/blobupload.go +++ b/registry/handlers/blobupload.go @@ -172,7 +172,7 @@ func (buh *blobUploadHandler) PatchBlobData(w http.ResponseWriter, r *http.Reque ct := r.Header.Get("Content-Type") if ct != "" && ct != "application/octet-stream" { - buh.Errors = append(buh.Errors, errcode.ErrorCodeUnknown.WithDetail(fmt.Errorf("Bad Content-Type"))) + buh.Errors = append(buh.Errors, errcode.ErrorCodeUnknown.WithDetail(fmt.Errorf("bad Content-Type"))) // TODO(dmcgowan): encode error return } diff --git a/registry/handlers/hooks.go b/registry/handlers/hooks.go index e51df2b7..4a2b1be8 100644 --- a/registry/handlers/hooks.go +++ b/registry/handlers/hooks.go @@ -20,7 +20,7 @@ type logHook struct { func (hook *logHook) Fire(entry *logrus.Entry) error { addr := strings.Split(hook.Mail.Addr, ":") if len(addr) != 2 { - return errors.New("Invalid Mail Address") + return errors.New("invalid Mail Address") } host := addr[0] subject := fmt.Sprintf("[%s] %s: %s", entry.Level, host, entry.Message) @@ -37,7 +37,7 @@ func (hook *logHook) Fire(entry *logrus.Entry) error { if err := t.Execute(b, entry); err != nil { return err } - body := fmt.Sprintf("%s", b) + body := b.String() return hook.Mail.sendMail(subject, body) } diff --git a/registry/handlers/mail.go b/registry/handlers/mail.go index 9e884265..684b1b34 100644 --- a/registry/handlers/mail.go +++ b/registry/handlers/mail.go @@ -17,7 +17,7 @@ type mailer struct { func (mail *mailer) sendMail(subject, message string) error { addr := strings.Split(mail.Addr, ":") if len(addr) != 2 { - return errors.New("Invalid Mail Address") + return errors.New("invalid Mail Address") } host := addr[0] msg := []byte("To:" + strings.Join(mail.To, ";") + diff --git a/registry/proxy/proxyblobstore.go b/registry/proxy/proxyblobstore.go index fc59552b..9ca9c968 100644 --- a/registry/proxy/proxyblobstore.go +++ b/registry/proxy/proxyblobstore.go @@ -6,7 +6,6 @@ import ( "net/http" "strconv" "sync" - "time" "github.com/docker/distribution" dcontext "github.com/docker/distribution/context" @@ -15,9 +14,6 @@ import ( "github.com/opencontainers/go-digest" ) -// todo(richardscothern): from cache control header or config file -const blobTTL = 24 * 7 * time.Hour - type proxyBlobStore struct { localStore distribution.BlobStore remoteStore distribution.BlobService diff --git a/registry/proxy/proxyblobstore_test.go b/registry/proxy/proxyblobstore_test.go index 4bf4ea8a..6e90dbe5 100644 --- a/registry/proxy/proxyblobstore_test.go +++ b/registry/proxy/proxyblobstore_test.go @@ -193,7 +193,7 @@ func makeTestEnv(t *testing.T, name string) *testEnv { } func makeBlob(size int) []byte { - blob := make([]byte, size, size) + blob := make([]byte, size) for i := 0; i < size; i++ { blob[i] = byte('A' + rand.Int()%48) } @@ -204,16 +204,6 @@ func init() { rand.Seed(42) } -func perm(m []distribution.Descriptor) []distribution.Descriptor { - for i := 0; i < len(m); i++ { - j := rand.Intn(i + 1) - tmp := m[i] - m[i] = m[j] - m[j] = tmp - } - return m -} - func populate(t *testing.T, te *testEnv, blobCount, size, numUnique int) { var inRemote []distribution.Descriptor diff --git a/registry/proxy/proxymanifeststore_test.go b/registry/proxy/proxymanifeststore_test.go index 99aaed28..82a1a2b7 100644 --- a/registry/proxy/proxymanifeststore_test.go +++ b/registry/proxy/proxymanifeststore_test.go @@ -165,11 +165,10 @@ func populateRepo(ctx context.Context, t *testing.T, repository distribution.Rep t.Fatalf("unexpected error creating test upload: %v", err) } - rs, ts, err := testutil.CreateRandomTarFile() + rs, dgst, err := testutil.CreateRandomTarFile() if err != nil { t.Fatalf("unexpected error generating test layer file") } - dgst := digest.Digest(ts) if _, err := io.Copy(wr, rs); err != nil { t.Fatalf("unexpected error copying to upload: %v", err) } diff --git a/registry/proxy/scheduler/scheduler.go b/registry/proxy/scheduler/scheduler.go index f8340184..f3c1caa0 100644 --- a/registry/proxy/scheduler/scheduler.go +++ b/registry/proxy/scheduler/scheduler.go @@ -118,7 +118,7 @@ func (ttles *TTLExpirationScheduler) Start() error { } if !ttles.stopped { - return fmt.Errorf("Scheduler already started") + return fmt.Errorf("scheduler already started") } dcontext.GetLogger(ttles.ctx).Infof("Starting cached object TTL expiration scheduler...") @@ -126,7 +126,7 @@ func (ttles *TTLExpirationScheduler) Start() error { // Start timer for each deserialized entry for _, entry := range ttles.entries { - entry.timer = ttles.startTimer(entry, entry.Expiry.Sub(time.Now())) + entry.timer = ttles.startTimer(entry, time.Until(entry.Expiry)) } // Start a ticker to periodically save the entries index @@ -164,7 +164,7 @@ func (ttles *TTLExpirationScheduler) add(r reference.Reference, ttl time.Duratio Expiry: time.Now().Add(ttl), EntryType: eType, } - dcontext.GetLogger(ttles.ctx).Infof("Adding new scheduler entry for %s with ttl=%s", entry.Key, entry.Expiry.Sub(time.Now())) + dcontext.GetLogger(ttles.ctx).Infof("Adding new scheduler entry for %s with ttl=%s", entry.Key, time.Until(entry.Expiry)) if oldEntry, present := ttles.entries[entry.Key]; present && oldEntry.timer != nil { oldEntry.timer.Stop() } diff --git a/registry/registry.go b/registry/registry.go index fd50b46a..03ff3fd7 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -201,7 +201,7 @@ func (registry *Registry) ListenAndServe() error { } if ok := pool.AppendCertsFromPEM(caPem); !ok { - return fmt.Errorf("Could not add CA to pool") + return fmt.Errorf("could not add CA to pool") } } diff --git a/registry/storage/blobstore.go b/registry/storage/blobstore.go index 9fdf5219..1008aad8 100644 --- a/registry/storage/blobstore.go +++ b/registry/storage/blobstore.go @@ -152,16 +152,6 @@ func (bs *blobStore) readlink(ctx context.Context, path string) (digest.Digest, return linked, nil } -// resolve reads the digest link at path and returns the blob store path. -func (bs *blobStore) resolve(ctx context.Context, path string) (string, error) { - dgst, err := bs.readlink(ctx, path) - if err != nil { - return "", err - } - - return bs.path(dgst) -} - type blobStatter struct { driver driver.StorageDriver } diff --git a/registry/storage/driver/azure/azure.go b/registry/storage/driver/azure/azure.go index 906e7792..58c6293b 100644 --- a/registry/storage/driver/azure/azure.go +++ b/registry/storage/driver/azure/azure.go @@ -55,17 +55,17 @@ func (factory *azureDriverFactory) Create(parameters map[string]interface{}) (st func FromParameters(parameters map[string]interface{}) (*Driver, error) { accountName, ok := parameters[paramAccountName] if !ok || fmt.Sprint(accountName) == "" { - return nil, fmt.Errorf("No %s parameter provided", paramAccountName) + return nil, fmt.Errorf("no %s parameter provided", paramAccountName) } accountKey, ok := parameters[paramAccountKey] if !ok || fmt.Sprint(accountKey) == "" { - return nil, fmt.Errorf("No %s parameter provided", paramAccountKey) + return nil, fmt.Errorf("no %s parameter provided", paramAccountKey) } container, ok := parameters[paramContainer] if !ok || fmt.Sprint(container) == "" { - return nil, fmt.Errorf("No %s parameter provided", paramContainer) + return nil, fmt.Errorf("no %s parameter provided", paramContainer) } realm, ok := parameters[paramRealm] diff --git a/registry/storage/driver/inmemory/mfs.go b/registry/storage/driver/inmemory/mfs.go index cdefacfd..9a2865f9 100644 --- a/registry/storage/driver/inmemory/mfs.go +++ b/registry/storage/driver/inmemory/mfs.go @@ -252,20 +252,6 @@ func (d *dir) delete(p string) error { return nil } -// dump outputs a primitive directory structure to stdout. -func (d *dir) dump(indent string) { - fmt.Println(indent, d.name()+"/") - - for _, child := range d.children { - if child.isdir() { - child.(*dir).dump(indent + "\t") - } else { - fmt.Println(indent, child.name()) - } - - } -} - func (d *dir) String() string { return fmt.Sprintf("&dir{path: %v, children: %v}", d.p, d.children) } diff --git a/registry/storage/driver/s3-aws/s3.go b/registry/storage/driver/s3-aws/s3.go index 800435d0..126a07f6 100644 --- a/registry/storage/driver/s3-aws/s3.go +++ b/registry/storage/driver/s3-aws/s3.go @@ -188,19 +188,19 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { regionName := parameters["region"] if regionName == nil || fmt.Sprint(regionName) == "" { - return nil, fmt.Errorf("No region parameter provided") + return nil, fmt.Errorf("no region parameter provided") } region := fmt.Sprint(regionName) // Don't check the region value if a custom endpoint is provided. if regionEndpoint == "" { if _, ok := validRegions[region]; !ok { - return nil, fmt.Errorf("Invalid region provided: %v", region) + return nil, fmt.Errorf("invalid region provided: %v", region) } } bucket := parameters["bucket"] if bucket == nil || fmt.Sprint(bucket) == "" { - return nil, fmt.Errorf("No bucket parameter provided") + return nil, fmt.Errorf("no bucket parameter provided") } encryptBool := false @@ -209,7 +209,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { case string: b, err := strconv.ParseBool(encrypt) if err != nil { - return nil, fmt.Errorf("The encrypt parameter should be a boolean") + return nil, fmt.Errorf("the encrypt parameter should be a boolean") } encryptBool = b case bool: @@ -217,7 +217,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { case nil: // do nothing default: - return nil, fmt.Errorf("The encrypt parameter should be a boolean") + return nil, fmt.Errorf("the encrypt parameter should be a boolean") } secureBool := true @@ -226,7 +226,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { case string: b, err := strconv.ParseBool(secure) if err != nil { - return nil, fmt.Errorf("The secure parameter should be a boolean") + return nil, fmt.Errorf("the secure parameter should be a boolean") } secureBool = b case bool: @@ -234,7 +234,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { case nil: // do nothing default: - return nil, fmt.Errorf("The secure parameter should be a boolean") + return nil, fmt.Errorf("the secure parameter should be a boolean") } skipVerifyBool := false @@ -243,7 +243,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { case string: b, err := strconv.ParseBool(skipVerify) if err != nil { - return nil, fmt.Errorf("The skipVerify parameter should be a boolean") + return nil, fmt.Errorf("the skipVerify parameter should be a boolean") } skipVerifyBool = b case bool: @@ -251,7 +251,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { case nil: // do nothing default: - return nil, fmt.Errorf("The skipVerify parameter should be a boolean") + return nil, fmt.Errorf("the skipVerify parameter should be a boolean") } v4Bool := true @@ -260,7 +260,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { case string: b, err := strconv.ParseBool(v4auth) if err != nil { - return nil, fmt.Errorf("The v4auth parameter should be a boolean") + return nil, fmt.Errorf("the v4auth parameter should be a boolean") } v4Bool = b case bool: @@ -268,7 +268,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { case nil: // do nothing default: - return nil, fmt.Errorf("The v4auth parameter should be a boolean") + return nil, fmt.Errorf("the v4auth parameter should be a boolean") } keyID := parameters["keyid"] @@ -306,7 +306,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { if storageClassParam != nil { storageClassString, ok := storageClassParam.(string) if !ok { - return nil, fmt.Errorf("The storageclass parameter must be one of %v, %v invalid", + return nil, fmt.Errorf("the storageclass parameter must be one of %v, %v invalid", []string{s3.StorageClassStandard, s3.StorageClassReducedRedundancy}, storageClassParam) } // All valid storage class parameters are UPPERCASE, so be a bit more flexible here @@ -314,7 +314,7 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { if storageClassString != noStorageClass && storageClassString != s3.StorageClassStandard && storageClassString != s3.StorageClassReducedRedundancy { - return nil, fmt.Errorf("The storageclass parameter must be one of %v, %v invalid", + return nil, fmt.Errorf("the storageclass parameter must be one of %v, %v invalid", []string{noStorageClass, s3.StorageClassStandard, s3.StorageClassReducedRedundancy}, storageClassParam) } storageClass = storageClassString @@ -330,11 +330,11 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { if objectACLParam != nil { objectACLString, ok := objectACLParam.(string) if !ok { - return nil, fmt.Errorf("Invalid value for objectacl parameter: %v", objectACLParam) + return nil, fmt.Errorf("invalid value for objectacl parameter: %v", objectACLParam) } if _, ok = validObjectACLs[objectACLString]; !ok { - return nil, fmt.Errorf("Invalid value for objectacl parameter: %v", objectACLParam) + return nil, fmt.Errorf("invalid value for objectacl parameter: %v", objectACLParam) } objectACL = objectACLString } @@ -389,7 +389,7 @@ func getParameterAsInt64(parameters map[string]interface{}, name string, default } if rv < min || rv > max { - return 0, fmt.Errorf("The %s %#v parameter should be a number between %d and %d (inclusive)", name, rv, min, max) + return 0, fmt.Errorf("the %s %#v parameter should be a number between %d and %d (inclusive)", name, rv, min, max) } return rv, nil @@ -401,7 +401,7 @@ func New(params DriverParameters) (*Driver, error) { if !params.V4Auth && (params.RegionEndpoint == "" || strings.Contains(params.RegionEndpoint, "s3.amazonaws.com")) { - return nil, fmt.Errorf("On Amazon S3 this storage driver can only be used with v4 authentication") + return nil, fmt.Errorf("on Amazon S3 this storage driver can only be used with v4 authentication") } awsConfig := aws.NewConfig() @@ -878,7 +878,7 @@ func (d *driver) URLFor(ctx context.Context, path string, options map[string]int if ok { et, ok := expires.(time.Time) if ok { - expiresIn = et.Sub(time.Now()) + expiresIn = time.Until(et) } } diff --git a/registry/storage/driver/s3-aws/s3_v2_signer.go b/registry/storage/driver/s3-aws/s3_v2_signer.go index 29688ae5..9f1e621c 100644 --- a/registry/storage/driver/s3-aws/s3_v2_signer.go +++ b/registry/storage/driver/s3-aws/s3_v2_signer.go @@ -39,12 +39,6 @@ import ( log "github.com/sirupsen/logrus" ) -const ( - signatureVersion = "2" - signatureMethod = "HmacSHA1" - timeFormat = "2006-01-02T15:04:05Z" -) - type signer struct { // Values that must be populated from the request Request *http.Request diff --git a/registry/storage/driver/swift/swift.go b/registry/storage/driver/swift/swift.go index 46201ee7..adbe8aa9 100644 --- a/registry/storage/driver/swift/swift.go +++ b/registry/storage/driver/swift/swift.go @@ -160,23 +160,23 @@ func FromParameters(parameters map[string]interface{}) (*Driver, error) { } if params.Username == "" { - return nil, fmt.Errorf("No username parameter provided") + return nil, fmt.Errorf("no username parameter provided") } if params.Password == "" { - return nil, fmt.Errorf("No password parameter provided") + return nil, fmt.Errorf("no password parameter provided") } if params.AuthURL == "" { - return nil, fmt.Errorf("No authurl parameter provided") + return nil, fmt.Errorf("no authurl parameter provided") } if params.Container == "" { - return nil, fmt.Errorf("No container parameter provided") + return nil, fmt.Errorf("no container parameter provided") } if params.ChunkSize < minChunkSize { - return nil, fmt.Errorf("The chunksize %#v parameter should be a number that is larger than or equal to %d", params.ChunkSize, minChunkSize) + return nil, fmt.Errorf("the chunksize %#v parameter should be a number that is larger than or equal to %d", params.ChunkSize, minChunkSize) } return New(params) @@ -211,15 +211,15 @@ func New(params Parameters) (*Driver, error) { } err := ct.Authenticate() if err != nil { - return nil, fmt.Errorf("Swift authentication failed: %s", err) + return nil, fmt.Errorf("swift authentication failed: %s", err) } if _, _, err := ct.Container(params.Container); err == swift.ContainerNotFound { if err := ct.ContainerCreate(params.Container, nil); err != nil { - return nil, fmt.Errorf("Failed to create container %s (%s)", params.Container, err) + return nil, fmt.Errorf("failed to create container %s (%s)", params.Container, err) } } else if err != nil { - return nil, fmt.Errorf("Failed to retrieve info about container %s (%s)", params.Container, err) + return nil, fmt.Errorf("failed to retrieve info about container %s (%s)", params.Container, err) } d := &driver{ @@ -258,7 +258,7 @@ func New(params Parameters) (*Driver, error) { if d.TempURLContainerKey { _, containerHeaders, err := d.Conn.Container(d.Container) if err != nil { - return nil, fmt.Errorf("Failed to fetch container info %s (%s)", d.Container, err) + return nil, fmt.Errorf("failed to fetch container info %s (%s)", d.Container, err) } d.SecretKey = containerHeaders["X-Container-Meta-Temp-Url-Key"] @@ -273,7 +273,7 @@ func New(params Parameters) (*Driver, error) { // Use the account secret key _, accountHeaders, err := d.Conn.Account() if err != nil { - return nil, fmt.Errorf("Failed to fetch account info (%s)", err) + return nil, fmt.Errorf("failed to fetch account info (%s)", err) } d.SecretKey = accountHeaders["X-Account-Meta-Temp-Url-Key"] @@ -350,7 +350,7 @@ func (d *driver) Reader(ctx context.Context, path string, offset int64) (io.Read } if isDLO && size == 0 { if time.Now().Add(waitingTime).After(endTime) { - return nil, fmt.Errorf("Timeout expired while waiting for segments of %s to show up", path) + return nil, fmt.Errorf("timeout expired while waiting for segments of %s to show up", path) } time.Sleep(waitingTime) waitingTime *= 2 @@ -456,7 +456,7 @@ func (d *driver) Stat(ctx context.Context, path string) (storagedriver.FileInfo, _, isDLO := headers["X-Object-Manifest"] if isDLO && info.Bytes == 0 { if time.Now().Add(waitingTime).After(endTime) { - return nil, fmt.Errorf("Timeout expired while waiting for segments of %s to show up", path) + return nil, fmt.Errorf("timeout expired while waiting for segments of %s to show up", path) } time.Sleep(waitingTime) waitingTime *= 2 @@ -755,7 +755,7 @@ func chunkFilenames(slice []string, maxSize int) (chunks [][]string, err error) chunks = append(chunks, slice[offset:offset+chunkSize]) } } else { - return nil, fmt.Errorf("Max chunk size must be > 0") + return nil, fmt.Errorf("max chunk size must be > 0") } return } @@ -894,7 +894,7 @@ func (w *writer) waitForSegmentsToShowUp() error { if info.Bytes == w.size { break } - err = fmt.Errorf("Timeout expired while waiting for segments of %s to show up", w.path) + err = fmt.Errorf("timeout expired while waiting for segments of %s to show up", w.path) } if time.Now().Add(waitingTime).After(endTime) { break diff --git a/registry/storage/linkedblobstore_test.go b/registry/storage/linkedblobstore_test.go index e0ffd279..7682b45c 100644 --- a/registry/storage/linkedblobstore_test.go +++ b/registry/storage/linkedblobstore_test.go @@ -27,13 +27,12 @@ func TestLinkedBlobStoreCreateWithMountFrom(t *testing.T) { // readseekers for upload later. testLayers := map[digest.Digest]io.ReadSeeker{} for i := 0; i < 2; i++ { - rs, ds, err := testutil.CreateRandomTarFile() + rs, dgst, err := testutil.CreateRandomTarFile() if err != nil { t.Fatalf("unexpected error generating test layer file") } - dgst := digest.Digest(ds) - testLayers[digest.Digest(dgst)] = rs + testLayers[dgst] = rs } // upload the layers to foo/bar diff --git a/registry/storage/manifeststore_test.go b/registry/storage/manifeststore_test.go index 2b3177b8..cfe18c12 100644 --- a/registry/storage/manifeststore_test.go +++ b/registry/storage/manifeststore_test.go @@ -91,13 +91,12 @@ func testManifestStorage(t *testing.T, schema1Enabled bool, options ...RegistryO // readseekers for upload later. testLayers := map[digest.Digest]io.ReadSeeker{} for i := 0; i < 2; i++ { - rs, ds, err := testutil.CreateRandomTarFile() + rs, dgst, err := testutil.CreateRandomTarFile() if err != nil { t.Fatalf("unexpected error generating test layer file") } - dgst := digest.Digest(ds) - testLayers[digest.Digest(dgst)] = rs + testLayers[dgst] = rs m.FSLayers = append(m.FSLayers, schema1.FSLayer{ BlobSum: dgst, }) @@ -414,11 +413,10 @@ func testOCIManifestStorage(t *testing.T, testname string, includeMediaTypes boo // Add some layers for i := 0; i < 2; i++ { - rs, ds, err := testutil.CreateRandomTarFile() + rs, dgst, err := testutil.CreateRandomTarFile() if err != nil { t.Fatalf("%s: unexpected error generating test layer file", testname) } - dgst := digest.Digest(ds) wr, err := env.repository.Blobs(env.ctx).Create(env.ctx) if err != nil { diff --git a/registry/storage/paths.go b/registry/storage/paths.go index b6d9b9b5..2d1f5132 100644 --- a/registry/storage/paths.go +++ b/registry/storage/paths.go @@ -133,10 +133,7 @@ func pathFor(spec pathSpec) (string, error) { return path.Join(append(append(repoPrefix, v.name, "_manifests", "revisions"), components...)...), nil case manifestRevisionLinkPathSpec: - root, err := pathFor(manifestRevisionPathSpec{ - name: v.name, - revision: v.revision, - }) + root, err := pathFor(manifestRevisionPathSpec(v)) if err != nil { return "", err @@ -156,10 +153,7 @@ func pathFor(spec pathSpec) (string, error) { return path.Join(root, v.tag), nil case manifestTagCurrentPathSpec: - root, err := pathFor(manifestTagPathSpec{ - name: v.name, - tag: v.tag, - }) + root, err := pathFor(manifestTagPathSpec(v)) if err != nil { return "", err @@ -167,10 +161,7 @@ func pathFor(spec pathSpec) (string, error) { return path.Join(root, "current", "link"), nil case manifestTagIndexPathSpec: - root, err := pathFor(manifestTagPathSpec{ - name: v.name, - tag: v.tag, - }) + root, err := pathFor(manifestTagPathSpec(v)) if err != nil { return "", err @@ -178,11 +169,7 @@ func pathFor(spec pathSpec) (string, error) { return path.Join(root, "index"), nil case manifestTagIndexEntryLinkPathSpec: - root, err := pathFor(manifestTagIndexEntryPathSpec{ - name: v.name, - tag: v.tag, - revision: v.revision, - }) + root, err := pathFor(manifestTagIndexEntryPathSpec(v)) if err != nil { return "", err diff --git a/registry/storage/paths_test.go b/registry/storage/paths_test.go index 677a34b9..ab3b8445 100644 --- a/registry/storage/paths_test.go +++ b/registry/storage/paths_test.go @@ -10,7 +10,6 @@ func TestPathMapper(t *testing.T) { for _, testcase := range []struct { spec pathSpec expected string - err error }{ { spec: manifestRevisionPathSpec{ diff --git a/registry/storage/purgeuploads.go b/registry/storage/purgeuploads.go index 7ebd1604..cac92121 100644 --- a/registry/storage/purgeuploads.go +++ b/registry/storage/purgeuploads.go @@ -59,7 +59,7 @@ func PurgeUploads(ctx context.Context, driver storageDriver.StorageDriver, older // file, so gather files by UUID with a date from startedAt. func getOutstandingUploads(ctx context.Context, driver storageDriver.StorageDriver) (map[string]uploadData, []error) { var errors []error - uploads := make(map[string]uploadData, 0) + uploads := make(map[string]uploadData) inUploadDir := false root, err := pathFor(repositoriesRootPathSpec{}) diff --git a/registry/storage/purgeuploads_test.go b/registry/storage/purgeuploads_test.go index 23c553ba..398df2b6 100644 --- a/registry/storage/purgeuploads_test.go +++ b/registry/storage/purgeuploads_test.go @@ -118,7 +118,7 @@ func TestPurgeOnlyUploads(t *testing.T) { t.Fatalf(err.Error()) } nonUploadPath := strings.Replace(dataPath, "_upload", "_important", -1) - if strings.Index(nonUploadPath, "_upload") != -1 { + if strings.Contains(nonUploadPath, "_upload") { t.Fatalf("Non-upload path not created correctly") } @@ -132,7 +132,7 @@ func TestPurgeOnlyUploads(t *testing.T) { t.Error("Unexpected errors", errs) } for _, file := range deleted { - if strings.Index(file, "_upload") == -1 { + if !strings.Contains(file, "_upload") { t.Errorf("Non-upload file deleted") } } diff --git a/registry/storage/schema2manifesthandler.go b/registry/storage/schema2manifesthandler.go index acb3255b..25d9d84f 100644 --- a/registry/storage/schema2manifesthandler.go +++ b/registry/storage/schema2manifesthandler.go @@ -14,9 +14,8 @@ import ( ) var ( - errUnexpectedURL = errors.New("unexpected URL on layer") - errMissingURL = errors.New("missing URL on layer") - errInvalidURL = errors.New("invalid URL on layer") + errMissingURL = errors.New("missing URL on layer") + errInvalidURL = errors.New("invalid URL on layer") ) //schema2ManifestHandler is a ManifestHandler that covers schema2 manifests. diff --git a/registry/storage/tagstore.go b/registry/storage/tagstore.go index f80b9628..a3c766b4 100644 --- a/registry/storage/tagstore.go +++ b/registry/storage/tagstore.go @@ -50,25 +50,6 @@ func (ts *tagStore) All(ctx context.Context) ([]string, error) { return tags, nil } -// exists returns true if the specified manifest tag exists in the repository. -func (ts *tagStore) exists(ctx context.Context, tag string) (bool, error) { - tagPath, err := pathFor(manifestTagCurrentPathSpec{ - name: ts.repository.Named().Name(), - tag: tag, - }) - - if err != nil { - return false, err - } - - exists, err := exists(ctx, ts.blobStore.driver, tagPath) - if err != nil { - return false, err - } - - return exists, nil -} - // Tag tags the digest with the given tag, updating the the store to point at // the current tag. The digest must point to a manifest. func (ts *tagStore) Tag(ctx context.Context, tag string, desc distribution.Descriptor) error { diff --git a/registry/storage/util.go b/registry/storage/util.go deleted file mode 100644 index 8ab235e2..00000000 --- a/registry/storage/util.go +++ /dev/null @@ -1,22 +0,0 @@ -package storage - -import ( - "context" - - "github.com/docker/distribution/registry/storage/driver" -) - -// Exists provides a utility method to test whether or not a path exists in -// the given driver. -func exists(ctx context.Context, drv driver.StorageDriver, path string) (bool, error) { - if _, err := drv.Stat(ctx, path); err != nil { - switch err := err.(type) { - case driver.PathNotFoundError: - return false, nil - default: - return false, err - } - } - - return true, nil -}