From 879453eaf16675f732dd87fd250ccaaac72f4285 Mon Sep 17 00:00:00 2001 From: haircommander Date: Mon, 23 Jul 2018 12:56:24 -0400 Subject: Fix ambiguity in adding localhost to podman save ...and some naming decisions. This change ensures podman save doesn't incorrectly prepend localhost when saving an image. Signed-off-by: haircommander Closes: #1140 Approved by: rhatdan --- cmd/podman/save.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'cmd') diff --git a/cmd/podman/save.go b/cmd/podman/save.go index 6a0d12885..f5fd421a4 100644 --- a/cmd/podman/save.go +++ b/cmd/podman/save.go @@ -145,7 +145,6 @@ func saveCmd(c *cli.Context) error { return err } } - if err := newImage.PushImageToReference(getContext(), destRef, manifestType, "", "", writer, c.Bool("compress"), libpodImage.SigningOptions{}, &libpodImage.DockerRegistryOptions{}, false, additionaltags); err != nil { if err2 := os.Remove(output); err2 != nil { logrus.Errorf("error deleting %q: %v", output, err) @@ -165,12 +164,15 @@ func imageNameForSaveDestination(img *libpodImage.Image, imgUserInput string) st } prepend := "" - if !strings.Contains(imgUserInput, libpodImage.DefaultLocalRepo) { + localRegistryPrefix := fmt.Sprintf("%s/", libpodImage.DefaultLocalRegistry) + if !strings.HasPrefix(imgUserInput, localRegistryPrefix) { // we need to check if localhost was added to the image name in NewFromLocal for _, name := range img.Names() { - // if the user searched for the image whose tag was prepended with localhost, we'll need to prepend localhost to successfully search - if strings.Contains(name, libpodImage.DefaultLocalRepo) && strings.Contains(name, imgUserInput) { - prepend = fmt.Sprintf("%s/", libpodImage.DefaultLocalRepo) + // If the user is saving an image in the localhost registry, getLocalImage need + // a name that matches the format localhost/: or localhost/:latest to correctly + // set up the manifest and save. + if strings.HasPrefix(name, localRegistryPrefix) && (strings.HasSuffix(name, imgUserInput) || strings.HasSuffix(name, fmt.Sprintf("%s:latest", imgUserInput))) { + prepend = localRegistryPrefix break } } -- cgit v1.2.3-54-g00ecf