From b8a1ec4155ffe83bd147cfdbac1d113111aa3e8e Mon Sep 17 00:00:00 2001 From: Richard Scothern Date: Fri, 18 Sep 2015 11:00:44 -0700 Subject: [PATCH] Avoid returning nil, nil when fetching a manifest by tag by introducing a new error ErrManifestNotModified which can be checked by clients. Signed-off-by: Richard Scothern --- docs/client/repository.go | 2 +- docs/client/repository_test.go | 7 ++----- docs/proxy/proxymanifeststore.go | 4 ++-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/docs/client/repository.go b/docs/client/repository.go index 2d198314..0fcb17dc 100644 --- a/docs/client/repository.go +++ b/docs/client/repository.go @@ -288,7 +288,7 @@ func (ms *manifests) GetByTag(tag string, options ...distribution.ManifestServic } defer resp.Body.Close() if resp.StatusCode == http.StatusNotModified { - return nil, nil + return nil, distribution.ErrManifestNotModified } else if SuccessStatus(resp.StatusCode) { var sm schema1.SignedManifest decoder := json.NewDecoder(resp.Body) diff --git a/docs/client/repository_test.go b/docs/client/repository_test.go index b211b1f9..6e4a017e 100644 --- a/docs/client/repository_test.go +++ b/docs/client/repository_test.go @@ -603,13 +603,10 @@ func TestManifestFetchWithEtag(t *testing.T) { t.Fatal(err) } - m2, err := ms.GetByTag("latest", AddEtagToTag("latest", d1.String())) - if err != nil { + _, err = ms.GetByTag("latest", AddEtagToTag("latest", d1.String())) + if err != distribution.ErrManifestNotModified { t.Fatal(err) } - if m2 != nil { - t.Fatal("Expected empty manifest for matching etag") - } } func TestManifestDelete(t *testing.T) { diff --git a/docs/proxy/proxymanifeststore.go b/docs/proxy/proxymanifeststore.go index 1400cf02..610d695e 100644 --- a/docs/proxy/proxymanifeststore.go +++ b/docs/proxy/proxymanifeststore.go @@ -102,11 +102,11 @@ func (pms proxyManifestStore) GetByTag(tag string, options ...distribution.Manif fromremote: var sm *schema1.SignedManifest sm, err = pms.remoteManifests.GetByTag(tag, client.AddEtagToTag(tag, localDigest.String())) - if err != nil { + if err != nil && err != distribution.ErrManifestNotModified { return nil, err } - if sm == nil { + if err == distribution.ErrManifestNotModified { context.GetLogger(pms.ctx).Debugf("Local manifest for %q is latest, dgst=%s", tag, localDigest.String()) return localManifest, nil }