ソースを参照

Add Extension() method to Compresison type

Guillaume J. Charmes 12 年 前
コミット
54db18625a
3 ファイル変更18 行追加2 行削除
  1. 0 1
      api.go
  2. 16 1
      archive.go
  3. 2 0
      buildfile.go

+ 0 - 1
api.go

@@ -9,7 +9,6 @@ import (
 	"io"
 	"log"
 	"net/http"
-	"os"
 	"strconv"
 	"strings"
 )

+ 16 - 1
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
 }

+ 2 - 0
buildfile.go

@@ -6,7 +6,9 @@ import (
 	"fmt"
 	"github.com/dotcloud/docker/utils"
 	"io"
+	"io/ioutil"
 	"os"
+	"path"
 	"reflect"
 	"strings"
 )