aboutsummaryrefslogtreecommitdiff
path: root/libpod/image
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2020-02-07 02:16:34 +0100
committerMiloslav Trmač <mitr@redhat.com>2020-02-07 23:36:01 +0100
commit933edf4a3767a1431257ba9d2948821eba967c23 (patch)
tree9edca03effdb3639e61c3a39f843c79dbc2bb90c /libpod/image
parent1ab4038807eb1586901460119820a4b865ac644f (diff)
downloadpodman-933edf4a3767a1431257ba9d2948821eba967c23.tar.gz
podman-933edf4a3767a1431257ba9d2948821eba967c23.tar.bz2
podman-933edf4a3767a1431257ba9d2948821eba967c23.zip
Move Image.getLocalImage to Runtime.getLocalImage
Instead of the function updating image.InputName (the only reason for it to need an image), have it return the updated value separately. This will allow simplifying the constructors of Image further. Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Diffstat (limited to 'libpod/image')
-rw-r--r--libpod/image/image.go51
1 files changed, 25 insertions, 26 deletions
diff --git a/libpod/image/image.go b/libpod/image/image.go
index 7efac4214..9cfcf3c67 100644
--- a/libpod/image/image.go
+++ b/libpod/image/image.go
@@ -125,16 +125,15 @@ func (ir *Runtime) newFromStorage(img *storage.Image) *Image {
// to only deal with local images already in the store (or
// its aliases)
func (ir *Runtime) NewFromLocal(name string) (*Image, error) {
- image := Image{
- InputName: name,
- imageruntime: ir,
- }
- localImage, err := image.getLocalImage()
+ updatedInputName, localImage, err := ir.getLocalImage(name)
if err != nil {
return nil, err
}
- image.image = localImage
- return &image, nil
+ return &Image{
+ InputName: updatedInputName,
+ imageruntime: ir,
+ image: localImage,
+ }, nil
}
// New creates a new image object where the image could be local
@@ -232,60 +231,60 @@ func stripSha256(name string) string {
}
// getLocalImage resolves an unknown input describing an image and
-// returns a storage.Image or an error. It is used by NewFromLocal.
-func (i *Image) getLocalImage() (*storage.Image, error) {
- imageError := fmt.Sprintf("unable to find '%s' in local storage", i.InputName)
- if i.InputName == "" {
- return nil, errors.Errorf("input name is blank")
+// returns an updated input name, and a storage.Image, or an error. It is used by NewFromLocal.
+func (ir *Runtime) getLocalImage(inputName string) (string, *storage.Image, error) {
+ imageError := fmt.Sprintf("unable to find '%s' in local storage", inputName)
+ if inputName == "" {
+ return "", nil, errors.Errorf("input name is blank")
}
// Check if the input name has a transport and if so strip it
- dest, err := alltransports.ParseImageName(i.InputName)
+ dest, err := alltransports.ParseImageName(inputName)
if err == nil && dest.DockerReference() != nil {
- i.InputName = dest.DockerReference().String()
+ inputName = dest.DockerReference().String()
}
- img, err := i.imageruntime.getImage(stripSha256(i.InputName))
+ img, err := ir.getImage(stripSha256(inputName))
if err == nil {
- return img.image, err
+ return inputName, img.image, err
}
// container-storage wasn't able to find it in its current form
// check if the input name has a tag, and if not, run it through
// again
- decomposedImage, err := decompose(i.InputName)
+ decomposedImage, err := decompose(inputName)
if err != nil {
- return nil, err
+ return "", nil, err
}
// The image has a registry name in it and we made sure we looked for it locally
// with a tag. It cannot be local.
if decomposedImage.hasRegistry {
- return nil, errors.Wrapf(ErrNoSuchImage, imageError)
+ return "", nil, errors.Wrapf(ErrNoSuchImage, imageError)
}
// if the image is saved with the repository localhost, searching with localhost prepended is necessary
// We don't need to strip the sha because we have already determined it is not an ID
ref, err := decomposedImage.referenceWithRegistry(DefaultLocalRegistry)
if err != nil {
- return nil, err
+ return "", nil, err
}
- img, err = i.imageruntime.getImage(ref.String())
+ img, err = ir.getImage(ref.String())
if err == nil {
- return img.image, err
+ return inputName, img.image, err
}
// grab all the local images
- images, err := i.imageruntime.GetImages()
+ images, err := ir.GetImages()
if err != nil {
- return nil, err
+ return "", nil, err
}
// check the repotags of all images for a match
repoImage, err := findImageInRepotags(decomposedImage, images)
if err == nil {
- return repoImage, nil
+ return inputName, repoImage, nil
}
- return nil, errors.Wrapf(ErrNoSuchImage, err.Error())
+ return "", nil, errors.Wrapf(ErrNoSuchImage, err.Error())
}
// ID returns the image ID as a string