summaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2021-02-22 15:08:40 +0100
committerValentin Rothberg <rothberg@redhat.com>2021-02-22 16:45:30 +0100
commit8577be72e8ec7fa597c7196bca0705d2c66083e0 (patch)
treeced9c1306f672f02954bd0c9ef0b60e4ded98484 /cmd/podman
parent10d52c05e23e75b9c608e100999cb55334732525 (diff)
downloadpodman-8577be72e8ec7fa597c7196bca0705d2c66083e0.tar.gz
podman-8577be72e8ec7fa597c7196bca0705d2c66083e0.tar.bz2
podman-8577be72e8ec7fa597c7196bca0705d2c66083e0.zip
podman cp: treat /dev/stdout correctly
/dev/stdout should not be treated as "-" to remain compatible with Docker and to have a more consistent and idiomatic interface. Fixes: #9362 Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/containers/cp.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/cmd/podman/containers/cp.go b/cmd/podman/containers/cp.go
index d3b904412..b29a95707 100644
--- a/cmd/podman/containers/cp.go
+++ b/cmd/podman/containers/cp.go
@@ -121,7 +121,9 @@ func copyFromContainer(container string, containerPath string, hostPath string)
return err
}
+ isStdout := false
if hostPath == "-" {
+ isStdout = true
hostPath = os.Stdout.Name()
}
@@ -152,10 +154,16 @@ func copyFromContainer(container string, containerPath string, hostPath string)
hostBaseName = filepath.Base(hostInfo.LinkTarget)
}
+ if !isStdout {
+ if err := validateFileInfo(hostInfo); err != nil {
+ return errors.Wrap(err, "invalid destination")
+ }
+ }
+
reader, writer := io.Pipe()
hostCopy := func() error {
defer reader.Close()
- if hostInfo.LinkTarget == os.Stdout.Name() {
+ if isStdout {
_, err := io.Copy(os.Stdout, reader)
return err
}
@@ -363,3 +371,12 @@ func containerParentDir(container string, containerPath string) (string, error)
workDir = filepath.Join(workDir, containerPath)
return filepath.Dir(workDir), nil
}
+
+// validateFileInfo returns an error if the specified FileInfo doesn't point to
+// a directory or a regular file.
+func validateFileInfo(info *copy.FileInfo) error {
+ if info.Mode.IsDir() || info.Mode.IsRegular() {
+ return nil
+ }
+ return errors.Errorf("%q must be a directory or a regular file", info.LinkTarget)
+}