summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2020-04-20 12:44:02 -0500
committerBrent Baude <bbaude@redhat.com>2020-04-21 09:23:27 -0500
commit29ec539b3ffad15624ee7934ec7dcbca2177db8e (patch)
tree7b724f29d07c1289f1578463fb2ed065b8db6626 /cmd
parentf4c2eb1d9dcff5feda5c3eae81ce1bcdbf166ec4 (diff)
downloadpodman-29ec539b3ffad15624ee7934ec7dcbca2177db8e.tar.gz
podman-29ec539b3ffad15624ee7934ec7dcbca2177db8e.tar.bz2
podman-29ec539b3ffad15624ee7934ec7dcbca2177db8e.zip
podmanv2 cp
enable podman to copy files between container and host, local mode only. this is a straight port of v1 code to v2. Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/containers/cp.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/cmd/podman/containers/cp.go b/cmd/podman/containers/cp.go
new file mode 100644
index 000000000..f0f9a158d
--- /dev/null
+++ b/cmd/podman/containers/cp.go
@@ -0,0 +1,55 @@
+package containers
+
+import (
+ "github.com/containers/libpod/cmd/podman/registry"
+ "github.com/containers/libpod/pkg/cgroups"
+ "github.com/containers/libpod/pkg/domain/entities"
+ "github.com/containers/libpod/pkg/rootless"
+ "github.com/sirupsen/logrus"
+ "github.com/spf13/cobra"
+)
+
+var (
+ cpDescription = `Command copies the contents of SRC_PATH to the DEST_PATH.
+
+ You can copy from the container's file system to the local machine or the reverse, from the local filesystem to the container. If "-" is specified for either the SRC_PATH or DEST_PATH, you can also stream a tar archive from STDIN or to STDOUT. The CONTAINER can be a running or stopped container. The SRC_PATH or DEST_PATH can be a file or directory.
+`
+ cpCommand = &cobra.Command{
+ Use: "cp [flags] SRC_PATH DEST_PATH",
+ Short: "Copy files/folders between a container and the local filesystem",
+ Long: cpDescription,
+ Args: cobra.ExactArgs(2),
+ RunE: cp,
+ Example: "podman cp [CONTAINER:]SRC_PATH [CONTAINER:]DEST_PATH",
+ }
+)
+
+var (
+ cpOpts entities.ContainerCpOptions
+)
+
+func init() {
+ registry.Commands = append(registry.Commands, registry.CliCommand{
+ Mode: []entities.EngineMode{entities.ABIMode},
+ Command: cpCommand,
+ })
+ flags := cpCommand.Flags()
+ flags.BoolVar(&cpOpts.Extract, "extract", false, "Extract the tar file into the destination directory.")
+ flags.BoolVar(&cpOpts.Pause, "pause", copyPause(), "Pause the container while copying")
+}
+
+func cp(cmd *cobra.Command, args []string) error {
+ _, err := registry.ContainerEngine().ContainerCp(registry.GetContext(), args[0], args[1], cpOpts)
+ return err
+}
+
+func copyPause() bool {
+ if rootless.IsRootless() {
+ cgroupv2, _ := cgroups.IsCgroup2UnifiedMode()
+ if !cgroupv2 {
+ logrus.Debugf("defaulting to pause==false on rootless cp in cgroupv1 systems")
+ return false
+ }
+ }
+ return true
+}