From 711ac9305185e645f2970d09ff76c2761132202a Mon Sep 17 00:00:00 2001 From: baude Date: Tue, 19 Feb 2019 10:08:43 -0600 Subject: podman-remote save [image] Add the ability to save an image from the remote-host to the remote-client. Signed-off-by: baude --- utils/utils.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'utils') 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) +} -- cgit v1.2.3-54-g00ecf