From 6847636c30bb3b70882000189946cb36cc5a246a Mon Sep 17 00:00:00 2001 From: baude Date: Thu, 4 Jan 2018 15:29:36 -0600 Subject: Remove by shortname Removing by shortname was not working. Also pruned container storage's remove func from rmi and moved it into an image.Remove func, which consolidates our usage of cs. Signed-off-by: baude Closes: #188 Approved by: baude --- libpod/runtime_img.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'libpod') diff --git a/libpod/runtime_img.go b/libpod/runtime_img.go index 6178d5372..66630beb2 100644 --- a/libpod/runtime_img.go +++ b/libpod/runtime_img.go @@ -184,6 +184,24 @@ func (k *Image) GetImageID() (string, error) { return img.ID, nil } } + // If the user input is an ID + images, err := k.runtime.GetImages(&ImageFilterParams{}) + if err != nil { + return "", errors.Wrapf(err, "unable to get images") + } + for _, image := range images { + // Check if we have an ID match + if strings.HasPrefix(image.ID, k.Name) { + return image.ID, nil + } + // Check if we have a name match, perhaps a tagged name + for _, name := range image.Names { + if k.Name == name { + return image.ID, nil + } + } + } + // If neither the ID is known and no local name // is know, we search it out. image, _ := k.GetFQName() @@ -408,6 +426,26 @@ func (k *Image) Pull(writer io.Writer) error { return nil } +// Remove calls into container storage and deletes the image +func (k *Image) Remove(force bool) (string, error) { + if k.LocalName == "" { + // This populates the images local name + _, err := k.GetLocalImageName() + if err != nil { + return "", errors.Wrapf(err, "unable to find %s locally", k.Name) + } + } + iid, err := k.GetImageID() + if err != nil { + return "", errors.Wrapf(err, "unable to get image id") + } + image, err := k.runtime.GetImage(iid) + if err != nil { + return "", errors.Wrapf(err, "unable to remove %s", iid) + } + return k.runtime.RemoveImage(image, force) +} + // GetRegistries gets the searchable registries from the global registration file. func GetRegistries() ([]string, error) { registryConfigPath := "" -- cgit v1.2.3-54-g00ecf