From c84e4513c8d849ef0433e4726ead81a1231d0510 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Mon, 15 Feb 2016 18:22:51 -0800 Subject: [PATCH] more vendoring --- .../hashicorp/go-getter/decompress.go | 29 +++++ .../hashicorp/go-getter/decompress_bzip2.go | 45 +++++++ .../hashicorp/go-getter/decompress_gzip.go | 49 +++++++ .../hashicorp/go-getter/decompress_tbz2.go | 95 ++++++++++++++ .../hashicorp/go-getter/decompress_testing.go | 121 ++++++++++++++++++ .../hashicorp/go-getter/decompress_tgz.go | 99 ++++++++++++++ .../hashicorp/go-getter/decompress_zip.go | 87 +++++++++++++ .../go-getter/test-fixtures/archive.tar.gz | Bin 0 -> 141 bytes .../basic-file-archive/archive.tar.gz | Bin 0 -> 141 bytes .../test-fixtures/decompress-bz2/single.bz2 | Bin 0 -> 40 bytes .../test-fixtures/decompress-gz/single.gz | Bin 0 -> 29 bytes .../decompress-tbz2/empty.tar.bz2 | Bin 0 -> 46 bytes .../decompress-tbz2/multiple.tar.bz2 | Bin 0 -> 166 bytes .../decompress-tbz2/single.tar.bz2 | Bin 0 -> 135 bytes .../test-fixtures/decompress-tgz/empty.tar.gz | Bin 0 -> 45 bytes .../decompress-tgz/multiple.tar.gz | Bin 0 -> 157 bytes .../decompress-tgz/single.tar.gz | Bin 0 -> 137 bytes .../test-fixtures/decompress-zip/empty.zip | Bin 0 -> 22 bytes .../test-fixtures/decompress-zip/multiple.zip | Bin 0 -> 306 bytes .../test-fixtures/decompress-zip/single.zip | Bin 0 -> 162 bytes 20 files changed, 525 insertions(+) create mode 100644 vendor/github.com/hashicorp/go-getter/decompress.go create mode 100644 vendor/github.com/hashicorp/go-getter/decompress_bzip2.go create mode 100644 vendor/github.com/hashicorp/go-getter/decompress_gzip.go create mode 100644 vendor/github.com/hashicorp/go-getter/decompress_tbz2.go create mode 100644 vendor/github.com/hashicorp/go-getter/decompress_testing.go create mode 100644 vendor/github.com/hashicorp/go-getter/decompress_tgz.go create mode 100644 vendor/github.com/hashicorp/go-getter/decompress_zip.go create mode 100644 vendor/github.com/hashicorp/go-getter/test-fixtures/archive.tar.gz create mode 100644 vendor/github.com/hashicorp/go-getter/test-fixtures/basic-file-archive/archive.tar.gz create mode 100644 vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-bz2/single.bz2 create mode 100644 vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-gz/single.gz create mode 100644 vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-tbz2/empty.tar.bz2 create mode 100644 vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-tbz2/multiple.tar.bz2 create mode 100644 vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-tbz2/single.tar.bz2 create mode 100644 vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-tgz/empty.tar.gz create mode 100644 vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-tgz/multiple.tar.gz create mode 100644 vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-tgz/single.tar.gz create mode 100644 vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-zip/empty.zip create mode 100644 vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-zip/multiple.zip create mode 100644 vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-zip/single.zip diff --git a/vendor/github.com/hashicorp/go-getter/decompress.go b/vendor/github.com/hashicorp/go-getter/decompress.go new file mode 100644 index 000000000..d18174cc3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-getter/decompress.go @@ -0,0 +1,29 @@ +package getter + +// Decompressor defines the interface that must be implemented to add +// support for decompressing a type. +type Decompressor interface { + // Decompress should decompress src to dst. dir specifies whether dst + // is a directory or single file. src is guaranteed to be a single file + // that exists. dst is not guaranteed to exist already. + Decompress(dst, src string, dir bool) error +} + +// Decompressors is the mapping of extension to the Decompressor implementation +// that will decompress that extension/type. +var Decompressors map[string]Decompressor + +func init() { + tbzDecompressor := new(TarBzip2Decompressor) + tgzDecompressor := new(TarGzipDecompressor) + + Decompressors = map[string]Decompressor{ + "bz2": new(Bzip2Decompressor), + "gz": new(GzipDecompressor), + "tar.bz2": tbzDecompressor, + "tar.gz": tgzDecompressor, + "tbz2": tbzDecompressor, + "tgz": tgzDecompressor, + "zip": new(ZipDecompressor), + } +} diff --git a/vendor/github.com/hashicorp/go-getter/decompress_bzip2.go b/vendor/github.com/hashicorp/go-getter/decompress_bzip2.go new file mode 100644 index 000000000..339f4cf7a --- /dev/null +++ b/vendor/github.com/hashicorp/go-getter/decompress_bzip2.go @@ -0,0 +1,45 @@ +package getter + +import ( + "compress/bzip2" + "fmt" + "io" + "os" + "path/filepath" +) + +// Bzip2Decompressor is an implementation of Decompressor that can +// decompress bz2 files. +type Bzip2Decompressor struct{} + +func (d *Bzip2Decompressor) Decompress(dst, src string, dir bool) error { + // Directory isn't supported at all + if dir { + return fmt.Errorf("bzip2-compressed files can only unarchive to a single file") + } + + // If we're going into a directory we should make that first + if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil { + return err + } + + // File first + f, err := os.Open(src) + if err != nil { + return err + } + defer f.Close() + + // Bzip2 compression is second + bzipR := bzip2.NewReader(f) + + // Copy it out + dstF, err := os.Create(dst) + if err != nil { + return err + } + defer dstF.Close() + + _, err = io.Copy(dstF, bzipR) + return err +} diff --git a/vendor/github.com/hashicorp/go-getter/decompress_gzip.go b/vendor/github.com/hashicorp/go-getter/decompress_gzip.go new file mode 100644 index 000000000..20010540e --- /dev/null +++ b/vendor/github.com/hashicorp/go-getter/decompress_gzip.go @@ -0,0 +1,49 @@ +package getter + +import ( + "compress/gzip" + "fmt" + "io" + "os" + "path/filepath" +) + +// GzipDecompressor is an implementation of Decompressor that can +// decompress bz2 files. +type GzipDecompressor struct{} + +func (d *GzipDecompressor) Decompress(dst, src string, dir bool) error { + // Directory isn't supported at all + if dir { + return fmt.Errorf("gzip-compressed files can only unarchive to a single file") + } + + // If we're going into a directory we should make that first + if err := os.MkdirAll(filepath.Dir(dst), 0755); err != nil { + return err + } + + // File first + f, err := os.Open(src) + if err != nil { + return err + } + defer f.Close() + + // gzip compression is second + gzipR, err := gzip.NewReader(f) + if err != nil { + return err + } + defer gzipR.Close() + + // Copy it out + dstF, err := os.Create(dst) + if err != nil { + return err + } + defer dstF.Close() + + _, err = io.Copy(dstF, gzipR) + return err +} diff --git a/vendor/github.com/hashicorp/go-getter/decompress_tbz2.go b/vendor/github.com/hashicorp/go-getter/decompress_tbz2.go new file mode 100644 index 000000000..c46ed4453 --- /dev/null +++ b/vendor/github.com/hashicorp/go-getter/decompress_tbz2.go @@ -0,0 +1,95 @@ +package getter + +import ( + "archive/tar" + "compress/bzip2" + "fmt" + "io" + "os" + "path/filepath" +) + +// TarBzip2Decompressor is an implementation of Decompressor that can +// decompress tar.bz2 files. +type TarBzip2Decompressor struct{} + +func (d *TarBzip2Decompressor) Decompress(dst, src string, dir bool) error { + // If we're going into a directory we should make that first + mkdir := dst + if !dir { + mkdir = filepath.Dir(dst) + } + if err := os.MkdirAll(mkdir, 0755); err != nil { + return err + } + + // File first + f, err := os.Open(src) + if err != nil { + return err + } + defer f.Close() + + // Bzip2 compression is second + bzipR := bzip2.NewReader(f) + + // Once bzip decompressed we have a tar format + tarR := tar.NewReader(bzipR) + done := false + for { + hdr, err := tarR.Next() + if err == io.EOF { + if !done { + // Empty archive + return fmt.Errorf("empty archive: %s", src) + } + + return nil + } + if err != nil { + return err + } + + path := dst + if dir { + path = filepath.Join(path, hdr.Name) + } + + if hdr.FileInfo().IsDir() { + if dir { + return fmt.Errorf("expected a single file: %s", src) + } + + // A directory, just make the directory and continue unarchiving... + if err := os.MkdirAll(path, 0755); err != nil { + return err + } + + continue + } + + // We have a file. If we already decoded, then it is an error + if !dir && done { + return fmt.Errorf("expected a single file, got multiple: %s", src) + } + + // Mark that we're done so future in single file mode errors + done = true + + // Open the file for writing + dstF, err := os.Create(path) + if err != nil { + return err + } + _, err = io.Copy(dstF, tarR) + dstF.Close() + if err != nil { + return err + } + + // Chmod the file + if err := os.Chmod(path, hdr.FileInfo().Mode()); err != nil { + return err + } + } +} diff --git a/vendor/github.com/hashicorp/go-getter/decompress_testing.go b/vendor/github.com/hashicorp/go-getter/decompress_testing.go new file mode 100644 index 000000000..5821ed66e --- /dev/null +++ b/vendor/github.com/hashicorp/go-getter/decompress_testing.go @@ -0,0 +1,121 @@ +package getter + +import ( + "crypto/md5" + "encoding/hex" + "io" + "io/ioutil" + "os" + "path/filepath" + "reflect" + "sort" + "strings" + "testing" +) + +// TestDecompressCase is a single test case for testing decompressors +type TestDecompressCase struct { + Input string // Input is the complete path to the input file + Dir bool // Dir is whether or not we're testing directory mode + Err bool // Err is whether we expect an error or not + DirList []string // DirList is the list of files for Dir mode + FileMD5 string // FileMD5 is the expected MD5 for a single file +} + +// TestDecompressor is a helper function for testing generic decompressors. +func TestDecompressor(t *testing.T, d Decompressor, cases []TestDecompressCase) { + for _, tc := range cases { + t.Logf("Testing: %s", tc.Input) + + // Temporary dir to store stuff + td, err := ioutil.TempDir("", "getter") + if err != nil { + t.Fatalf("err: %s", err) + } + + // Destination is always joining result so that we have a new path + dst := filepath.Join(td, "subdir", "result") + + // We use a function so defers work + func() { + defer os.RemoveAll(td) + + // Decompress + err := d.Decompress(dst, tc.Input, tc.Dir) + if (err != nil) != tc.Err { + t.Fatalf("err %s: %s", tc.Input, err) + } + if tc.Err { + return + } + + // If it isn't a directory, then check for a single file + if !tc.Dir { + fi, err := os.Stat(dst) + if err != nil { + t.Fatalf("err %s: %s", tc.Input, err) + } + if fi.IsDir() { + t.Fatalf("err %s: expected file, got directory", tc.Input) + } + if tc.FileMD5 != "" { + actual := testMD5(t, dst) + expected := tc.FileMD5 + if actual != expected { + t.Fatalf("err %s: expected MD5 %s, got %s", tc.Input, expected, actual) + } + } + + return + } + + // Directory, check for the correct contents + actual := testListDir(t, dst) + expected := tc.DirList + if !reflect.DeepEqual(actual, expected) { + t.Fatalf("bad %s\n\n%#v\n\n%#v", tc.Input, actual, expected) + } + }() + } +} + +func testListDir(t *testing.T, path string) []string { + var result []string + err := filepath.Walk(path, func(sub string, info os.FileInfo, err error) error { + if err != nil { + return err + } + + sub = strings.TrimPrefix(sub, path) + if sub == "" { + return nil + } + sub = sub[1:] // Trim the leading path sep. + + result = append(result, sub) + return nil + }) + if err != nil { + t.Fatalf("err: %s", err) + } + + sort.Strings(result) + return result +} + +func testMD5(t *testing.T, path string) string { + f, err := os.Open(path) + if err != nil { + t.Fatalf("err: %s", err) + } + defer f.Close() + + h := md5.New() + _, err = io.Copy(h, f) + if err != nil { + t.Fatalf("err: %s", err) + } + + result := h.Sum(nil) + return hex.EncodeToString(result) +} diff --git a/vendor/github.com/hashicorp/go-getter/decompress_tgz.go b/vendor/github.com/hashicorp/go-getter/decompress_tgz.go new file mode 100644 index 000000000..391bbc0ad --- /dev/null +++ b/vendor/github.com/hashicorp/go-getter/decompress_tgz.go @@ -0,0 +1,99 @@ +package getter + +import ( + "archive/tar" + "compress/gzip" + "fmt" + "io" + "os" + "path/filepath" +) + +// TarGzipDecompressor is an implementation of Decompressor that can +// decompress tar.gzip files. +type TarGzipDecompressor struct{} + +func (d *TarGzipDecompressor) Decompress(dst, src string, dir bool) error { + // If we're going into a directory we should make that first + mkdir := dst + if !dir { + mkdir = filepath.Dir(dst) + } + if err := os.MkdirAll(mkdir, 0755); err != nil { + return err + } + + // File first + f, err := os.Open(src) + if err != nil { + return err + } + defer f.Close() + + // Gzip compression is second + gzipR, err := gzip.NewReader(f) + if err != nil { + return fmt.Errorf("Error opening a gzip reader for %s: %s", src, err) + } + defer gzipR.Close() + + // Once gzip decompressed we have a tar format + tarR := tar.NewReader(gzipR) + done := false + for { + hdr, err := tarR.Next() + if err == io.EOF { + if !done { + // Empty archive + return fmt.Errorf("empty archive: %s", src) + } + + return nil + } + if err != nil { + return err + } + + path := dst + if dir { + path = filepath.Join(path, hdr.Name) + } + + if hdr.FileInfo().IsDir() { + if dir { + return fmt.Errorf("expected a single file: %s", src) + } + + // A directory, just make the directory and continue unarchiving... + if err := os.MkdirAll(path, 0755); err != nil { + return err + } + + continue + } + + // We have a file. If we already decoded, then it is an error + if !dir && done { + return fmt.Errorf("expected a single file, got multiple: %s", src) + } + + // Mark that we're done so future in single file mode errors + done = true + + // Open the file for writing + dstF, err := os.Create(path) + if err != nil { + return err + } + _, err = io.Copy(dstF, tarR) + dstF.Close() + if err != nil { + return err + } + + // Chmod the file + if err := os.Chmod(path, hdr.FileInfo().Mode()); err != nil { + return err + } + } +} diff --git a/vendor/github.com/hashicorp/go-getter/decompress_zip.go b/vendor/github.com/hashicorp/go-getter/decompress_zip.go new file mode 100644 index 000000000..0e4f6d739 --- /dev/null +++ b/vendor/github.com/hashicorp/go-getter/decompress_zip.go @@ -0,0 +1,87 @@ +package getter + +import ( + "archive/zip" + "fmt" + "io" + "os" + "path/filepath" +) + +// ZipDecompressor is an implementation of Decompressor that can +// decompress tar.gzip files. +type ZipDecompressor struct{} + +func (d *ZipDecompressor) Decompress(dst, src string, dir bool) error { + // If we're going into a directory we should make that first + mkdir := dst + if !dir { + mkdir = filepath.Dir(dst) + } + if err := os.MkdirAll(mkdir, 0755); err != nil { + return err + } + + // Open the zip + zipR, err := zip.OpenReader(src) + if err != nil { + return err + } + defer zipR.Close() + + // Check the zip integrity + if len(zipR.File) == 0 { + // Empty archive + return fmt.Errorf("empty archive: %s", src) + } + if !dir && len(zipR.File) > 1 { + return fmt.Errorf("expected a single file: %s", src) + } + + // Go through and unarchive + for _, f := range zipR.File { + path := dst + if dir { + path = filepath.Join(path, f.Name) + } + + if f.FileInfo().IsDir() { + if dir { + return fmt.Errorf("expected a single file: %s", src) + } + + // A directory, just make the directory and continue unarchiving... + if err := os.MkdirAll(path, 0755); err != nil { + return err + } + + continue + } + + // Open the file for reading + srcF, err := f.Open() + if err != nil { + return err + } + + // Open the file for writing + dstF, err := os.Create(path) + if err != nil { + srcF.Close() + return err + } + _, err = io.Copy(dstF, srcF) + srcF.Close() + dstF.Close() + if err != nil { + return err + } + + // Chmod the file + if err := os.Chmod(path, f.Mode()); err != nil { + return err + } + } + + return nil +} diff --git a/vendor/github.com/hashicorp/go-getter/test-fixtures/archive.tar.gz b/vendor/github.com/hashicorp/go-getter/test-fixtures/archive.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..999e5fc9d6974cb108aa94abadac6e2aecfac0dc GIT binary patch literal 141 zcmb2|=3qGQG&PKY`RxTqu4V_G*2L?!u6_YV$#X3GJ=j^-Ug-NCzIsRYLT=60|F>wZ`SUo>_I@-Y%CIzaj8qGbEc>?kDFXw;K?Vi^Mur6piZdizBw|mBJalrree3)b00(*wbpQYW literal 0 HcmV?d00001 diff --git a/vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-gz/single.gz b/vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-gz/single.gz new file mode 100644 index 0000000000000000000000000000000000000000..00754d02d1b766c6fe83562c04e4a1a3c389596d GIT binary patch literal 29 kcmb2|=HL+Yn;OQzoR*oB%HVza{BtIT6{$vbEDQ_`0DQX$Hvj+t literal 0 HcmV?d00001 diff --git a/vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-tbz2/empty.tar.bz2 b/vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-tbz2/empty.tar.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..a70463740ad1149f75a68a13fc3c0fc7b22c68fd GIT binary patch literal 46 zcmZ>Y%CIzaj8qGbjI7@Agn>aMfZ+fG3j+g(0)xRBR?TI?N$TA@mF8%8=kY5~ literal 0 HcmV?d00001 diff --git a/vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-tbz2/multiple.tar.bz2 b/vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-tbz2/multiple.tar.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..1d59e6ad2ce760bf7ff834cee8570812ae501c24 GIT binary patch literal 166 zcmV;X09pS+T4*^jL0KkKS*=**^Z)>``;gHP2#`Pke}Di8Yi6DR1ONaiFaWqlG{j*V zU;qHdn2aM#000G2H8h%;lru)7C#jS5O`9*CnlxbJKvO7z7UyBRg2+OM-B@PTMx>`H zWZ)vlH64^mMhc_9WTiTM;^eF)#j7-}RthNzu1dCASsqclX3q}yyBF&hr=||A9vHbi UuDR^Hq9EA2k}1N3g=)typwQSw`2YX_ literal 0 HcmV?d00001 diff --git a/vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-tbz2/single.tar.bz2 b/vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-tbz2/single.tar.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..115f9a4aeb2ce15195187c8952191b17e5155fbb GIT binary patch literal 135 zcmV;20C@jGT4*^jL0KkKSq`FV*Z=^5dyvr(2!TKVe}Di4Yi6DR1ONaCAOLhAjWq$F zH1!%Z)6^1BKr{x800~R&VFw`vR3s!?@alJNC#0hYyhCR~w{Pwah*C7LewukF%UHc4vzO8hz+9IHtv3LJQ!E(`&M))_)b(-tu-EZ2c*ZQKSU{X&+{@V9FCik+x?$Cc89r@HscY5K8 z$~!Z(lUK#RTPbfi--cuE^UL?F6YQgYy_eemG5Y`STmL=&|8M-q%zywgw}qcRy!Dnr HgMk46B&J9$ literal 0 HcmV?d00001 diff --git a/vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-tgz/single.tar.gz b/vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-tgz/single.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..921bdacc6f6c00c099f7f64a3bfd1dc5d4859cbe GIT binary patch literal 137 zcmb2|=3q!Sn;OQz{Pw&fSF?dYYvOg=qcVv;NmX(aSz1LFZvAd9Rk-|tlh?!lX8nzc z6~gTzt7flURqi*f=2x1pY3e8 jr&}fb-%W8(Id3m`{Nu;hd<@8-;dPo|NzQQw4F(1PJX<=r literal 0 HcmV?d00001 diff --git a/vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-zip/empty.zip b/vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-zip/empty.zip new file mode 100644 index 0000000000000000000000000000000000000000..15cb0ecb3e219d1701294bfdf0fe3f5cb5d208e7 GIT binary patch literal 22 NcmWIWW@Tf*000g10H*)| literal 0 HcmV?d00001 diff --git a/vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-zip/multiple.zip b/vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-zip/multiple.zip new file mode 100644 index 0000000000000000000000000000000000000000..a032181d43b89865241dd9e1d05dc5712706267d GIT binary patch literal 306 zcmWIWW@h1H0D%o5Ivy)hjp|r{Y!GH;kYPy6%tzw+5H!Mwun~+*a?H5gApx|AfdObG!;(f23+gIXh^x?C6yQy)QO;1KfUd)3 S6e}CZJ|-ZX2Bh0S90mY1;x;}2 literal 0 HcmV?d00001 diff --git a/vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-zip/single.zip b/vendor/github.com/hashicorp/go-getter/test-fixtures/decompress-zip/single.zip new file mode 100644 index 0000000000000000000000000000000000000000..90687fde18f0470ec513362f7cc06ae17b0abf62 GIT binary patch literal 162 zcmWIWW@h1H00Ey69gh{MMs+MeHU!Hsq-Ex$hK6u5FdMi}4KoJf(h6<{MwYLPKqVqT zb!qweTmjyUOmfV)%#Z*X%>Y!-u%r>hf|$q(F%iwQ0B=?{kQzoH^a9dOAPxfna#|Ph literal 0 HcmV?d00001