Call imageNameForSaveDestination while creating the references

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č <mitr@redhat.com>

Closes: #1176
Approved by: rhatdan
This commit is contained in:
Miloslav Trmač 2018-07-28 03:50:30 +02:00 committed by Atomic Bot
parent 18c4e2c835
commit 754fc8e8ec
1 changed files with 9 additions and 9 deletions

View File

@ -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)
}