summaryrefslogtreecommitdiff
path: root/cmd/podman/save.go
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2018-07-28 03:43:03 +0200
committerAtomic Bot <atomic-devel@projectatomic.io>2018-08-01 18:22:58 +0000
commitc27c6c67075b295bb3f0f6ebc6c5919cf208e4e4 (patch)
treebf50c4274b48420863357a89acb9bb5e0ec43ef4 /cmd/podman/save.go
parenta4b15548d1c402266eb93ba74bb60f6daf24ee6e (diff)
downloadpodman-c27c6c67075b295bb3f0f6ebc6c5919cf208e4e4.tar.gz
podman-c27c6c67075b295bb3f0f6ebc6c5919cf208e4e4.tar.bz2
podman-c27c6c67075b295bb3f0f6ebc6c5919cf208e4e4.zip
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
Diffstat (limited to 'cmd/podman/save.go')
-rw-r--r--cmd/podman/save.go34
1 files changed, 21 insertions, 13 deletions
diff --git a/cmd/podman/save.go b/cmd/podman/save.go
index 577a22358..1f4b1ce7f 100644
--- a/cmd/podman/save.go
+++ b/cmd/podman/save.go
@@ -129,19 +129,9 @@ 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) {
- if !strings.Contains(newImage.ID(), source) {
- prepend := ""
- if !strings.Contains(source, libpodImage.DefaultLocalRepo) {
- // we need to check if localhost was added to the image name in NewFromLocal
- for _, name := range newImage.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, source) {
- prepend = fmt.Sprintf("%s/", libpodImage.DefaultLocalRepo)
- break
- }
- }
- }
- dest = fmt.Sprintf("%s:%s%s", dst, prepend, source)
+ 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 {
@@ -153,3 +143,21 @@ func saveCmd(c *cli.Context) error {
return nil
}
+
+func imageNameForSaveDestination(newImage *libpodImage.Image, source string) string {
+ if !strings.Contains(newImage.ID(), source) {
+ prepend := ""
+ if !strings.Contains(source, libpodImage.DefaultLocalRepo) {
+ // we need to check if localhost was added to the image name in NewFromLocal
+ for _, name := range newImage.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, source) {
+ prepend = fmt.Sprintf("%s/", libpodImage.DefaultLocalRepo)
+ break
+ }
+ }
+ }
+ return fmt.Sprintf("%s%s", prepend, source)
+ }
+ return ""
+}