]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/github.com/hashicorp/go-getter/decompress_tgz.go
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / go-getter / decompress_tgz.go
index e8b1c31cacd4d596f6f4e0191ac583d2bc11f96f..65eb70dd2c2d96cbe88e2300592aff8fa57b91cf 100644 (file)
@@ -1,10 +1,8 @@
 package getter
 
 import (
-       "archive/tar"
        "compress/gzip"
        "fmt"
-       "io"
        "os"
        "path/filepath"
 )
@@ -37,63 +35,5 @@ func (d *TarGzipDecompressor) Decompress(dst, src string, dir bool) error {
        }
        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
-               }
-       }
+       return untar(gzipR, dst, src, dir)
 }