diff options
-rw-r--r-- | cmd/podman/create.go | 30 | ||||
-rw-r--r-- | libpod/runtime_img.go | 28 |
2 files changed, 20 insertions, 38 deletions
diff --git a/cmd/podman/create.go b/cmd/podman/create.go index 80cb7f432..e0825566a 100644 --- a/cmd/podman/create.go +++ b/cmd/podman/create.go @@ -370,10 +370,13 @@ func exposedPorts(c *cli.Context, imageExposedPorts map[string]struct{}) (map[na // default container runtime data out of it. imageData returns the data // to the caller. Example Data: Entrypoint, Env, WorkingDir, Labels ... func imageData(c *cli.Context, runtime *libpod.Runtime, image string) (string, string, *libpod.ImageData, error) { - var err error + var ( + err error + imageName, imageID string + ) // Deal with the image after all the args have been checked createImage := runtime.NewImage(image) - createImage.LocalName, _ = createImage.GetLocalImageName() + imageName, imageID, _ = createImage.GetLocalImageName() if createImage.LocalName == "" { // The image wasnt found by the user input'd name or its fqname // Pull the image @@ -384,31 +387,14 @@ func imageData(c *cli.Context, runtime *libpod.Runtime, image string) (string, s createImage.Pull(writer) } - var imageName string - if createImage.LocalName != "" { - nameIsID, err := runtime.IsImageID(createImage.LocalName) - if err != nil { - return "", "", nil, err - } - if nameIsID { - // If the input from the user is an ID, then we need to get the image - // name for cstorage - createImage.LocalName, err = createImage.GetNameByID() - if err != nil { - return "", "", nil, err - } - } - imageName = createImage.LocalName - } else { + createImage.LocalName = imageName + if imageName == "" { imageName, err = createImage.GetFQName() + _, imageID, _ = createImage.GetLocalImageName() } if err != nil { return "", "", nil, err } - imageID, err := createImage.GetImageID() - if err != nil { - return "", "", nil, err - } storageImage, err := runtime.GetImage(imageName) if err != nil { return "", "", nil, errors.Wrapf(err, "error getting storage image %q", image) diff --git a/libpod/runtime_img.go b/libpod/runtime_img.go index 671e08c19..882174856 100644 --- a/libpod/runtime_img.go +++ b/libpod/runtime_img.go @@ -342,27 +342,23 @@ func getTags(nameInput string) (reference.NamedTagged, bool, error) { return tagged, isTagged, nil } -// GetLocalImageName returns the name of the image if it is local. -// It will return an empty string and error if not found. -func (k *Image) GetLocalImageName() (string, error) { - _, err := k.runtime.GetImage(k.Name) +// GetLocalImageName returns the name of the image if it is local as well +// as the image's ID. It will return an empty strings and error if not found. +func (k *Image) GetLocalImageName() (string, string, error) { + localImage, err := k.runtime.GetImage(k.Name) if err == nil { k.LocalName = k.Name - return k.Name, nil + return k.Name, localImage.ID, nil } localImages, err := k.runtime.GetImages(&ImageFilterParams{}) if err != nil { - return "", errors.Wrapf(err, "unable to find local images") + return "", "", errors.Wrapf(err, "unable to find local images") } _, isTagged, err := getTags(k.Name) if err != nil { - return "", err + return "", "", err } for _, image := range localImages { - if strings.HasPrefix(image.ID, k.Name) { - k.ID = image.ID - return image.ID, nil - } for _, name := range image.Names { imgRef, err := reference.Parse(name) if err != nil { @@ -382,22 +378,22 @@ func (k *Image) GetLocalImageName() (string, error) { if imageName == k.Name { k.LocalName = name - return name, nil + return name, image.ID, nil } imageSplit := strings.Split(imageName, "/") baseName := imageSplit[len(imageSplit)-1] if baseName == k.Name { k.LocalName = name - return name, nil + return name, image.ID, nil } } } - return "", errors.Wrapf(storage.ErrImageUnknown, "unable to find image locally") + return "", "", errors.Wrapf(storage.ErrImageUnknown, "unable to find image locally") } // HasLatest determines if we have the latest image local func (k *Image) HasLatest() (bool, error) { - localName, err := k.GetLocalImageName() + localName, _, err := k.GetLocalImageName() if err != nil { return false, err } @@ -434,7 +430,7 @@ func (k *Image) Pull(writer io.Writer) error { func (k *Image) Remove(force bool) (string, error) { if k.LocalName == "" { // This populates the images local name - _, err := k.GetLocalImageName() + _, _, err := k.GetLocalImageName() if err != nil { return "", errors.Wrapf(err, "unable to find %s locally", k.Name) } |