aboutsummaryrefslogtreecommitdiff
path: root/libpod/container.go
diff options
context:
space:
mode:
authorUrvashi Mohnani <umohnani@redhat.com>2017-11-21 16:51:17 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2017-11-22 16:17:06 +0000
commit2a3934f1dae43589c50df8fa545d20405f64d7af (patch)
tree57f61f01f7274bdfd733dfb01ecdb514c3f1cbd7 /libpod/container.go
parent91b406ea4a175a7b996f8810e1eb2f2653ff335d (diff)
downloadpodman-2a3934f1dae43589c50df8fa545d20405f64d7af.tar.gz
podman-2a3934f1dae43589c50df8fa545d20405f64d7af.tar.bz2
podman-2a3934f1dae43589c50df8fa545d20405f64d7af.zip
Update kpod export to use the new container state and runtime
Signed-off-by: Urvashi Mohnani <umohnani@redhat.com> Closes: #59 Approved by: rhatdan
Diffstat (limited to 'libpod/container.go')
-rw-r--r--libpod/container.go38
1 files changed, 37 insertions, 1 deletions
diff --git a/libpod/container.go b/libpod/container.go
index f167adc35..9b48d2ca1 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -3,12 +3,15 @@ package libpod
import (
"encoding/json"
"fmt"
+ "io"
"io/ioutil"
+ "os"
"path/filepath"
"sync"
"time"
"github.com/containers/storage"
+ "github.com/containers/storage/pkg/archive"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/pkg/term"
spec "github.com/opencontainers/runtime-spec/specs-go"
@@ -469,7 +472,40 @@ func (c *Container) Unpause() error {
// Export exports a container's root filesystem as a tar archive
// The archive will be saved as a file at the given path
func (c *Container) Export(path string) error {
- return ErrNotImplemented
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
+ if err := c.syncContainer(); err != nil {
+ return err
+ }
+
+ mountPoint := c.state.Mountpoint
+ if !c.state.Mounted {
+ mount, err := c.runtime.store.Mount(c.ID(), c.config.MountLabel)
+ if err != nil {
+ return errors.Wrapf(err, "error mounting container %q", c.ID())
+ }
+ mountPoint = mount
+ defer func() {
+ if err := c.runtime.store.Unmount(c.ID()); err != nil {
+ logrus.Errorf("error unmounting container %q: %v", c.ID(), err)
+ }
+ }()
+ }
+
+ input, err := archive.Tar(mountPoint, archive.Uncompressed)
+ if err != nil {
+ return errors.Wrapf(err, "error reading container directory %q", c.ID())
+ }
+
+ outFile, err := os.Create(path)
+ if err != nil {
+ return errors.Wrapf(err, "error creating file %q", path)
+ }
+ defer outFile.Close()
+
+ _, err = io.Copy(outFile, input)
+ return err
}
// Commit commits the changes between a container and its image, creating a new