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:
parent
a11e3bd5f9
commit
0fbfeb17e5
1 changed files with 18 additions and 4 deletions
|
@ -106,20 +106,29 @@ func (store *store) AddDigest(ref reference.Canonical, id digest.Digest, force b
|
|||
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
|
||||
// digest.
|
||||
canonical, isCanonical := ref.(reference.Canonical)
|
||||
_, isNamedTagged := ref.(reference.NamedTagged)
|
||||
canonical, isCanonical := originalRef.(reference.Canonical)
|
||||
_, isNamedTagged := originalRef.(reference.NamedTagged)
|
||||
|
||||
if isCanonical && isNamedTagged {
|
||||
trimmed, err := reference.WithDigest(reference.TrimNamed(canonical), canonical.Digest())
|
||||
if err != nil {
|
||||
// should never happen
|
||||
return err
|
||||
return originalRef, err
|
||||
}
|
||||
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)
|
||||
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
|
||||
// happened, or false otherwise.
|
||||
func (store *store) Delete(ref reference.Named) (bool, error) {
|
||||
ref, err := favorDigest(ref)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
ref = reference.TagNameOnly(ref)
|
||||
|
||||
refName := reference.FamiliarName(ref)
|
||||
|
|
Loading…
Reference in a new issue