2017-08-31 15:17:21 +00:00
|
|
|
package images
|
2017-07-24 13:21:50 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/containers/storage"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
// UntagImage removes the tag from the given image
|
|
|
|
func UntagImage(store storage.Store, image *storage.Image, imgArg string) (string, error) {
|
2017-07-24 15:14:18 +00:00
|
|
|
// Remove name from image.Names and set the new names
|
2017-07-24 13:21:50 +00:00
|
|
|
newNames := []string{}
|
|
|
|
removedName := ""
|
|
|
|
for _, name := range image.Names {
|
|
|
|
if MatchesReference(name, imgArg) {
|
|
|
|
removedName = name
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
newNames = append(newNames, name)
|
|
|
|
}
|
2017-07-24 15:14:18 +00:00
|
|
|
if removedName != "" {
|
|
|
|
if err := store.SetNames(image.ID, newNames); err != nil {
|
|
|
|
return "", errors.Wrapf(err, "error removing name %q from image %q", removedName, image.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return removedName, nil
|
2017-07-24 13:21:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveImage removes the given image from storage
|
|
|
|
func RemoveImage(image *storage.Image, store storage.Store) (string, error) {
|
2017-07-24 15:14:18 +00:00
|
|
|
_, err := store.DeleteImage(image.ID, true)
|
2017-07-24 13:21:50 +00:00
|
|
|
if err != nil {
|
2017-07-24 15:14:18 +00:00
|
|
|
return "", errors.Wrapf(err, "could not remove image %q", image.ID)
|
2017-07-24 13:21:50 +00:00
|
|
|
}
|
|
|
|
return image.ID, nil
|
|
|
|
}
|