reference: handle combination of tag and digest in ImageDelete

If you remove an image with digest+tag, it will fail because it wont
find it in the reference store (where digest+tag -> digest). Let's
make sure we do the same in ImageDelete, stripping the tag if
digest+tag are present.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2017-02-16 10:48:40 +01:00
parent a11e3bd5f9
commit 0fbfeb17e5
No known key found for this signature in database
GPG key ID: 083CC6FD6EB699A3

View file

@ -106,20 +106,29 @@ func (store *store) AddDigest(ref reference.Canonical, id digest.Digest, force b
return store.addReference(ref, id, force) return store.addReference(ref, id, force)
} }
func (store *store) addReference(ref reference.Named, id digest.Digest, force bool) error { func favorDigest(originalRef reference.Named) (reference.Named, error) {
ref := originalRef
// If the reference includes a digest and a tag, we must store only the // If the reference includes a digest and a tag, we must store only the
// digest. // digest.
canonical, isCanonical := ref.(reference.Canonical) canonical, isCanonical := originalRef.(reference.Canonical)
_, isNamedTagged := ref.(reference.NamedTagged) _, isNamedTagged := originalRef.(reference.NamedTagged)
if isCanonical && isNamedTagged { if isCanonical && isNamedTagged {
trimmed, err := reference.WithDigest(reference.TrimNamed(canonical), canonical.Digest()) trimmed, err := reference.WithDigest(reference.TrimNamed(canonical), canonical.Digest())
if err != nil { if err != nil {
// should never happen // should never happen
return err return originalRef, err
} }
ref = trimmed ref = trimmed
} }
return ref, nil
}
func (store *store) addReference(ref reference.Named, id digest.Digest, force bool) error {
ref, err := favorDigest(ref)
if err != nil {
return err
}
refName := reference.FamiliarName(ref) refName := reference.FamiliarName(ref)
refStr := reference.FamiliarString(ref) refStr := reference.FamiliarString(ref)
@ -169,6 +178,11 @@ func (store *store) addReference(ref reference.Named, id digest.Digest, force bo
// Delete deletes a reference from the store. It returns true if a deletion // Delete deletes a reference from the store. It returns true if a deletion
// happened, or false otherwise. // happened, or false otherwise.
func (store *store) Delete(ref reference.Named) (bool, error) { func (store *store) Delete(ref reference.Named) (bool, error) {
ref, err := favorDigest(ref)
if err != nil {
return false, err
}
ref = reference.TagNameOnly(ref) ref = reference.TagNameOnly(ref)
refName := reference.FamiliarName(ref) refName := reference.FamiliarName(ref)