From 754fc8e8ecf98ebd34140ee1414f96665d84b883 Mon Sep 17 00:00:00 2001 From: Miloslav Trmač Date: Sat, 28 Jul 2018 03:50:30 +0200 Subject: Call imageNameForSaveDestination while creating the references MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of creating a reference string and then checking it again to see which kind of archive it is, just call imageNameForSaveDestination at the place where we already know what kind of archive it is because we are making that decision. This also notably fixes the use of strings.CONTAINS to see whether the just constructed strings start with one of the transport names; that would match anywhere in the path. Signed-off-by: Miloslav Trmač Closes: #1176 Approved by: rhatdan --- cmd/podman/save.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'cmd/podman') diff --git a/cmd/podman/save.go b/cmd/podman/save.go index 15a7f85c8..bc5f816e8 100644 --- a/cmd/podman/save.go +++ b/cmd/podman/save.go @@ -103,6 +103,10 @@ func saveCmd(c *cli.Context) error { switch c.String("format") { case libpod.OCIArchive: dst = libpod.OCIArchive + ":" + output + destImageName := imageNameForSaveDestination(newImage, source) + if destImageName != "" { + dst = fmt.Sprintf("%s:%s", dst, destImageName) + } case "oci-dir": dst = libpod.DirTransport + ":" + output manifestType = imgspecv1.MediaTypeImageManifest @@ -113,6 +117,10 @@ func saveCmd(c *cli.Context) error { fallthrough case "": dst = libpod.DockerArchive + ":" + output + destImageName := imageNameForSaveDestination(newImage, source) + if destImageName != "" { + dst = fmt.Sprintf("%s:%s", dst, destImageName) + } default: return errors.Errorf("unknown format option %q", c.String("format")) } @@ -126,15 +134,7 @@ func saveCmd(c *cli.Context) error { } } - dest := dst - // need dest to be in the format transport:path:reference for the following transports - if strings.Contains(dst, libpod.OCIArchive) || strings.Contains(dst, libpod.DockerArchive) { - destImageName := imageNameForSaveDestination(newImage, source) - if destImageName != "" { - dest = fmt.Sprintf("%s:%s", dst, destImageName) - } - } - if err := newImage.PushImage(getContext(), dest, manifestType, "", "", writer, c.Bool("compress"), libpodImage.SigningOptions{}, &libpodImage.DockerRegistryOptions{}, false, additionaltags); err != nil { + if err := newImage.PushImage(getContext(), dst, 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) } -- cgit v1.2.3-54-g00ecf