aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-02-19 10:08:43 -0600
committerbaude <bbaude@redhat.com>2019-02-20 12:58:05 -0600
commit711ac9305185e645f2970d09ff76c2761132202a (patch)
treee8c7c83be19cc075446b20ea49a88c529dda69f1 /utils
parent4de0bf9c74624de8a2cab1e5cbebc0beaa67339a (diff)
downloadpodman-711ac9305185e645f2970d09ff76c2761132202a.tar.gz
podman-711ac9305185e645f2970d09ff76c2761132202a.tar.bz2
podman-711ac9305185e645f2970d09ff76c2761132202a.zip
podman-remote save [image]
Add the ability to save an image from the remote-host to the remote-client. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'utils')
-rw-r--r--utils/utils.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/utils/utils.go b/utils/utils.go
index 4a91b304f..33b0eb1c5 100644
--- a/utils/utils.go
+++ b/utils/utils.go
@@ -4,12 +4,15 @@ import (
"bytes"
"fmt"
"io"
+ "os"
"os/exec"
"strings"
+ "github.com/containers/storage/pkg/archive"
systemdDbus "github.com/coreos/go-systemd/dbus"
"github.com/godbus/dbus"
"github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
)
// ExecCmd executes a command with args and returns its output as a string along
@@ -139,3 +142,30 @@ func CopyDetachable(dst io.Writer, src io.Reader, keys []byte) (written int64, e
}
return written, err
}
+
+// UntarToFileSystem untars an os.file of a tarball to a destination in the filesystem
+func UntarToFileSystem(dest string, tarball *os.File, options *archive.TarOptions) error {
+ logrus.Debugf("untarring %s", tarball.Name())
+ return archive.Untar(tarball, dest, options)
+}
+
+// TarToFilesystem creates a tarball from source and writes to an os.file
+// provided
+func TarToFilesystem(source string, tarball *os.File) error {
+ tb, err := Tar(source)
+ if err != nil {
+ return err
+ }
+ _, err = io.Copy(tarball, tb)
+ if err != nil {
+ return err
+ }
+ logrus.Debugf("wrote tarball file %s", tarball.Name())
+ return nil
+}
+
+// Tar creates a tarball from source and returns a readcloser of it
+func Tar(source string) (io.ReadCloser, error) {
+ logrus.Debugf("creating tarball of %s", source)
+ return archive.Tar(source, archive.Uncompressed)
+}