mirror of
https://github.com/containers/podman.git
synced 2025-06-28 06:18:57 +08:00
Split imageNameForSaveDestination from saveCmd
We will need to call it from two places in the future. Should not change behavior, the code is pretty unchanged (down to using confusing parameter names, which we will change immediately) (but does not add unit tests). Signed-off-by: Miloslav Trmač <mitr@redhat.com> Closes: #1176 Approved by: rhatdan
This commit is contained in:

committed by
Atomic Bot

parent
a4b15548d1
commit
c27c6c6707
@ -129,6 +129,22 @@ 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 err2 := os.Remove(output); err2 != nil {
|
||||
logrus.Errorf("error deleting %q: %v", output, err)
|
||||
}
|
||||
return errors.Wrapf(err, "unable to save %q", args)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func imageNameForSaveDestination(newImage *libpodImage.Image, source string) string {
|
||||
if !strings.Contains(newImage.ID(), source) {
|
||||
prepend := ""
|
||||
if !strings.Contains(source, libpodImage.DefaultLocalRepo) {
|
||||
@ -141,15 +157,7 @@ func saveCmd(c *cli.Context) error {
|
||||
}
|
||||
}
|
||||
}
|
||||
dest = fmt.Sprintf("%s:%s%s", dst, prepend, source)
|
||||
return fmt.Sprintf("%s%s", prepend, source)
|
||||
}
|
||||
}
|
||||
if err := newImage.PushImage(getContext(), dest, 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)
|
||||
}
|
||||
return errors.Wrapf(err, "unable to save %q", args)
|
||||
}
|
||||
|
||||
return nil
|
||||
return ""
|
||||
}
|
||||
|
Reference in New Issue
Block a user