forked from containers/podman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
podman save uses named pipe as output path, not directly using /dev/stdout. fix containers#7017 Signed-off-by: Qi Wang <[email protected]>
- Loading branch information
Showing
4 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build !linux | ||
|
||
package images | ||
|
||
func setupPipe() (string, func() <-chan error, error) { | ||
return "/dev/stdout", nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters