summaryrefslogtreecommitdiff
path: root/libpod/runtime_ctr.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-01-27 09:57:44 -0600
committerbaude <bbaude@redhat.com>2019-02-05 10:05:41 -0600
commit64c8fb7c2460eb561c8496f781f26d65443eea59 (patch)
tree19a7bae6cd3bc117fa7b2e9dfe44d3534b4f75ed /libpod/runtime_ctr.go
parent3554bfce98bc643bd4724340bf2abbaa6373e70c (diff)
downloadpodman-64c8fb7c2460eb561c8496f781f26d65443eea59.tar.gz
podman-64c8fb7c2460eb561c8496f781f26d65443eea59.tar.bz2
podman-64c8fb7c2460eb561c8496f781f26d65443eea59.zip
podman-remote import|export
addition of import and export for the podman-remote client. This includes the ability to send and receive files between the remote-client and the "podman" host using an upgraded varlink connection. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'libpod/runtime_ctr.go')
-rw-r--r--libpod/runtime_ctr.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go
index 6d5ce5a7e..9afdef7b6 100644
--- a/libpod/runtime_ctr.go
+++ b/libpod/runtime_ctr.go
@@ -2,9 +2,11 @@ package libpod
import (
"context"
+ "io/ioutil"
"os"
"path"
"path/filepath"
+ "strconv"
"strings"
"time"
@@ -521,3 +523,44 @@ func isNamedVolume(volName string) bool {
}
return false
}
+
+// Export is the libpod portion of exporting a container to a tar file
+func (r *Runtime) Export(name string, path string) error {
+ ctr, err := r.LookupContainer(name)
+ if err != nil {
+ return err
+ }
+ if os.Geteuid() != 0 {
+ state, err := ctr.State()
+ if err != nil {
+ return errors.Wrapf(err, "cannot read container state %q", ctr.ID())
+ }
+ if state == ContainerStateRunning || state == ContainerStatePaused {
+ data, err := ioutil.ReadFile(ctr.Config().ConmonPidFile)
+ if err != nil {
+ return errors.Wrapf(err, "cannot read conmon PID file %q", ctr.Config().ConmonPidFile)
+ }
+ conmonPid, err := strconv.Atoi(string(data))
+ if err != nil {
+ return errors.Wrapf(err, "cannot parse PID %q", data)
+ }
+ became, ret, err := rootless.JoinDirectUserAndMountNS(uint(conmonPid))
+ if err != nil {
+ return err
+ }
+ if became {
+ os.Exit(ret)
+ }
+ } else {
+ became, ret, err := rootless.BecomeRootInUserNS()
+ if err != nil {
+ return err
+ }
+ if became {
+ os.Exit(ret)
+ }
+ }
+ }
+ return ctr.Export(path)
+
+}