diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-02-20 23:52:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-20 23:52:35 +0100 |
commit | 2cf2b7f8a688973010a4ce504ab4917cb4a85a15 (patch) | |
tree | e8c7c83be19cc075446b20ea49a88c529dda69f1 /utils | |
parent | 4de0bf9c74624de8a2cab1e5cbebc0beaa67339a (diff) | |
parent | 711ac9305185e645f2970d09ff76c2761132202a (diff) | |
download | podman-2cf2b7f8a688973010a4ce504ab4917cb4a85a15.tar.gz podman-2cf2b7f8a688973010a4ce504ab4917cb4a85a15.tar.bz2 podman-2cf2b7f8a688973010a4ce504ab4917cb4a85a15.zip |
Merge pull request #2367 from baude/remotesave
podman-remote save [image]
Diffstat (limited to 'utils')
-rw-r--r-- | utils/utils.go | 30 |
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) +} |