From 54db18625aa7154c9dd230907444676fa3079b99 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 28 May 2013 13:37:49 -0700 Subject: [PATCH] Add Extension() method to Compresison type --- api.go | 1 - archive.go | 17 ++++++++++++++++- buildfile.go | 2 ++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/api.go b/api.go index d3eb9101b7..a1a6949626 100644 --- a/api.go +++ b/api.go @@ -9,7 +9,6 @@ import ( "io" "log" "net/http" - "os" "strconv" "strings" ) diff --git a/archive.go b/archive.go index 8a011eb6e1..4120a52c1d 100644 --- a/archive.go +++ b/archive.go @@ -2,6 +2,7 @@ package docker import ( "errors" + "fmt" "io" "io/ioutil" "os" @@ -31,6 +32,20 @@ func (compression *Compression) Flag() string { return "" } +func (compression *Compression) Extension() string { + switch *compression { + case Uncompressed: + return "tar" + case Bzip2: + return "tar.bz2" + case Gzip: + return "tar.gz" + case Xz: + return "tar.xz" + } + return "" +} + func Tar(path string, compression Compression) (io.Reader, error) { cmd := exec.Command("bsdtar", "-f", "-", "-C", path, "-c"+compression.Flag(), ".") return CmdStream(cmd) @@ -41,7 +56,7 @@ func Untar(archive io.Reader, path string) error { cmd.Stdin = archive output, err := cmd.CombinedOutput() if err != nil { - return errors.New(err.Error() + ": " + string(output)) + return fmt.Errorf("%s: %s", err, output) } return nil } diff --git a/buildfile.go b/buildfile.go index 0784f54328..d0f0b6e7d7 100644 --- a/buildfile.go +++ b/buildfile.go @@ -6,7 +6,9 @@ import ( "fmt" "github.com/dotcloud/docker/utils" "io" + "io/ioutil" "os" + "path" "reflect" "strings" )