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 <richard.scothern@gmail.com>
This commit is contained in:
Richard Scothern 2015-09-18 11:00:44 -07:00
parent ece8e132bf
commit 924913b4c3
4 changed files with 11 additions and 9 deletions

View file

@ -1,15 +1,20 @@
package distribution package distribution
import ( import (
"errors"
"fmt" "fmt"
"strings" "strings"
"github.com/docker/distribution/digest" "github.com/docker/distribution/digest"
) )
// ErrManifestNotModified is returned when a conditional manifest GetByTag
// returns nil due to the client indicating it has the latest version
var ErrManifestNotModified = errors.New("manifest not modified")
// ErrUnsupported is returned when an unimplemented or unsupported action is // ErrUnsupported is returned when an unimplemented or unsupported action is
// performed // performed
var ErrUnsupported = fmt.Errorf("operation unsupported") var ErrUnsupported = errors.New("operation unsupported")
// ErrRepositoryUnknown is returned if the named repository is not known by // ErrRepositoryUnknown is returned if the named repository is not known by
// the registry. // the registry.

View file

@ -288,7 +288,7 @@ func (ms *manifests) GetByTag(tag string, options ...distribution.ManifestServic
} }
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode == http.StatusNotModified { if resp.StatusCode == http.StatusNotModified {
return nil, nil return nil, distribution.ErrManifestNotModified
} else if SuccessStatus(resp.StatusCode) { } else if SuccessStatus(resp.StatusCode) {
var sm schema1.SignedManifest var sm schema1.SignedManifest
decoder := json.NewDecoder(resp.Body) decoder := json.NewDecoder(resp.Body)

View file

@ -603,13 +603,10 @@ func TestManifestFetchWithEtag(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
m2, err := ms.GetByTag("latest", AddEtagToTag("latest", d1.String())) _, err = ms.GetByTag("latest", AddEtagToTag("latest", d1.String()))
if err != nil { if err != distribution.ErrManifestNotModified {
t.Fatal(err) t.Fatal(err)
} }
if m2 != nil {
t.Fatal("Expected empty manifest for matching etag")
}
} }
func TestManifestDelete(t *testing.T) { func TestManifestDelete(t *testing.T) {

View file

@ -102,11 +102,11 @@ func (pms proxyManifestStore) GetByTag(tag string, options ...distribution.Manif
fromremote: fromremote:
var sm *schema1.SignedManifest var sm *schema1.SignedManifest
sm, err = pms.remoteManifests.GetByTag(tag, client.AddEtagToTag(tag, localDigest.String())) sm, err = pms.remoteManifests.GetByTag(tag, client.AddEtagToTag(tag, localDigest.String()))
if err != nil { if err != nil && err != distribution.ErrManifestNotModified {
return nil, err 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()) context.GetLogger(pms.ctx).Debugf("Local manifest for %q is latest, dgst=%s", tag, localDigest.String())
return localManifest, nil return localManifest, nil
} }