summaryrefslogtreecommitdiff
path: root/cmd/podman/images/save.go
diff options
context:
space:
mode:
authorQi Wang <qiwan@redhat.com>2020-07-23 15:54:12 -0400
committerMatthew Heon <matthew.heon@pm.me>2020-08-20 12:16:52 -0400
commit34f4a892e4056dd660db85db6ee8baa0470dd6f2 (patch)
tree8c5604df8da7aedc414a9662924de771d31ee285 /cmd/podman/images/save.go
parentceae3a99d54154fac6073f30bba2618768d05362 (diff)
downloadpodman-34f4a892e4056dd660db85db6ee8baa0470dd6f2.tar.gz
podman-34f4a892e4056dd660db85db6ee8baa0470dd6f2.tar.bz2
podman-34f4a892e4056dd660db85db6ee8baa0470dd6f2.zip
podman save use named pipe
podman save uses named pipe as output path, not directly using /dev/stdout. fix #7017 Signed-off-by: Qi Wang <qiwan@redhat.com> <MH: Corrected imports during cherry-pick> Signed-off-by: Matt Heon <matthew.heon@pm.me>
Diffstat (limited to 'cmd/podman/images/save.go')
-rw-r--r--cmd/podman/images/save.go31
1 files changed, 25 insertions, 6 deletions
diff --git a/cmd/podman/images/save.go b/cmd/podman/images/save.go
index f84d97b17..00eb9f1e6 100644
--- a/cmd/podman/images/save.go
+++ b/cmd/podman/images/save.go
@@ -5,10 +5,9 @@ import (
"os"
"strings"
- "github.com/containers/libpod/v2/libpod/define"
-
"github.com/containers/libpod/v2/cmd/podman/parse"
"github.com/containers/libpod/v2/cmd/podman/registry"
+ "github.com/containers/libpod/v2/libpod/define"
"github.com/containers/libpod/v2/pkg/domain/entities"
"github.com/containers/libpod/v2/pkg/util"
"github.com/pkg/errors"
@@ -83,9 +82,10 @@ func saveFlags(flags *pflag.FlagSet) {
}
-func save(cmd *cobra.Command, args []string) error {
+func save(cmd *cobra.Command, args []string) (finalErr error) {
var (
- tags []string
+ tags []string
+ succeeded = false
)
if cmd.Flag("compress").Changed && (saveOpts.Format != define.OCIManifestDir && saveOpts.Format != define.V2s2ManifestDir && saveOpts.Format == "") {
return errors.Errorf("--compress can only be set when --format is either 'oci-dir' or 'docker-dir'")
@@ -95,7 +95,22 @@ func save(cmd *cobra.Command, args []string) error {
if terminal.IsTerminal(int(fi.Fd())) {
return errors.Errorf("refusing to save to terminal. Use -o flag or redirect")
}
- saveOpts.Output = "/dev/stdout"
+ pipePath, cleanup, err := setupPipe()
+ if err != nil {
+ return err
+ }
+ if cleanup != nil {
+ defer func() {
+ errc := cleanup()
+ if succeeded {
+ writeErr := <-errc
+ if writeErr != nil && finalErr == nil {
+ finalErr = writeErr
+ }
+ }
+ }()
+ }
+ saveOpts.Output = pipePath
}
if err := parse.ValidateFileName(saveOpts.Output); err != nil {
return err
@@ -103,5 +118,9 @@ func save(cmd *cobra.Command, args []string) error {
if len(args) > 1 {
tags = args[1:]
}
- return registry.ImageEngine().Save(context.Background(), args[0], tags, saveOpts)
+ err := registry.ImageEngine().Save(context.Background(), args[0], tags, saveOpts)
+ if err == nil {
+ succeeded = true
+ }
+ return err
}