diff options
author | Qi Wang <qiwan@redhat.com> | 2020-07-23 15:54:12 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2020-08-20 12:16:52 -0400 |
commit | 34f4a892e4056dd660db85db6ee8baa0470dd6f2 (patch) | |
tree | 8c5604df8da7aedc414a9662924de771d31ee285 /cmd/podman/images/utils_linux.go | |
parent | ceae3a99d54154fac6073f30bba2618768d05362 (diff) | |
download | podman-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/utils_linux.go')
-rw-r--r-- | cmd/podman/images/utils_linux.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/cmd/podman/images/utils_linux.go b/cmd/podman/images/utils_linux.go new file mode 100644 index 000000000..5521abab4 --- /dev/null +++ b/cmd/podman/images/utils_linux.go @@ -0,0 +1,47 @@ +package images + +import ( + "io" + "io/ioutil" + "os" + "path/filepath" + + "github.com/pkg/errors" + "github.com/sirupsen/logrus" + "golang.org/x/sys/unix" +) + +// setupPipe for fixing https://github.com/containers/podman/issues/7017 +// uses named pipe since containers/image EvalSymlinks fails with /dev/stdout +// the caller should use the returned function to clean up the pipeDir +func setupPipe() (string, func() <-chan error, error) { + errc := make(chan error) + pipeDir, err := ioutil.TempDir(os.TempDir(), "pipeDir") + if err != nil { + return "", nil, err + } + pipePath := filepath.Join(pipeDir, "saveio") + err = unix.Mkfifo(pipePath, 0600) + if err != nil { + if e := os.RemoveAll(pipeDir); e != nil { + logrus.Errorf("error removing named pipe: %q", e) + } + return "", nil, errors.Wrapf(err, "error creating named pipe") + } + go func() { + fpipe, err := os.Open(pipePath) + if err != nil { + errc <- err + return + } + _, err = io.Copy(os.Stdout, fpipe) + fpipe.Close() + errc <- err + }() + return pipePath, func() <-chan error { + if e := os.RemoveAll(pipeDir); e != nil { + logrus.Errorf("error removing named pipe: %q", e) + } + return errc + }, nil +} |