c8d/rmi: Handle explicit dangling name

This isn't something that user should do, but technically the dangling
images exist in the image store and user can pass its name (`moby-dangling@digest`).
Change it so rmi now recognizes that it's actually a dangling image and
doesn't handle it like a regular tagged image.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski 2023-10-06 10:14:31 +02:00
parent 25a813e924
commit b8ba263099
No known key found for this signature in database
GPG key ID: B85EFCFE26DEF92A
2 changed files with 5 additions and 2 deletions

View file

@ -64,7 +64,8 @@ func (i *ImageService) ImageDelete(ctx context.Context, imageRef string, force,
imgID := image.ID(img.Target.Digest)
if isImageIDPrefix(imgID.String(), imageRef) {
explicitDanglingRef := strings.HasPrefix(imageRef, imageNameDanglingPrefix) && isDanglingImage(img)
if isImageIDPrefix(imgID.String(), imageRef) || explicitDanglingRef {
return i.deleteAll(ctx, img, force, prune)
}

View file

@ -11,6 +11,8 @@ import (
"github.com/pkg/errors"
)
const imageNameDanglingPrefix = "moby-dangling@"
// softImageDelete deletes the image, making sure that there are other images
// that reference the content of the deleted image.
// If no other image exists, a dangling one is created.
@ -74,7 +76,7 @@ func (i *ImageService) ensureDanglingImage(ctx context.Context, from containerdi
}
func danglingImageName(digest digest.Digest) string {
return "moby-dangling@" + digest.String()
return imageNameDanglingPrefix + digest.String()
}
func isDanglingImage(image containerdimages.Image) bool {