c8d/softDelete: Deep copy Labels

So we don't override the original Labels in the passed image object.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
(cherry picked from commit a6d5db3f9b)
Signed-off-by: Bjorn Neergaard <bjorn.neergaard@docker.com>
This commit is contained in:
Paweł Gronowski 2023-06-30 09:37:45 +02:00 committed by Bjorn Neergaard
parent 8afe75ffa9
commit 8bf037b246
No known key found for this signature in database

View file

@ -53,9 +53,16 @@ func (i *ImageService) softImageDelete(ctx context.Context, img containerdimages
func (i *ImageService) ensureDanglingImage(ctx context.Context, from containerdimages.Image) error {
danglingImage := from
danglingImage.Labels = make(map[string]string)
for k, v := range from.Labels {
switch k {
case containerdimages.AnnotationImageName, ocispec.AnnotationRefName:
// Don't copy name labels.
default:
danglingImage.Labels[k] = v
}
}
danglingImage.Name = danglingImageName(from.Target.Digest)
delete(danglingImage.Labels, containerdimages.AnnotationImageName)
delete(danglingImage.Labels, ocispec.AnnotationRefName)
_, err := i.client.ImageService().Create(context.Background(), danglingImage)
// If it already exists, then just continue.