diff options
Diffstat (limited to 'vendor/github.com/hashicorp/go-getter/decompress_tar.go')
-rw-r--r-- | vendor/github.com/hashicorp/go-getter/decompress_tar.go | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/vendor/github.com/hashicorp/go-getter/decompress_tar.go b/vendor/github.com/hashicorp/go-getter/decompress_tar.go index 39cb392..b6986a2 100644 --- a/vendor/github.com/hashicorp/go-getter/decompress_tar.go +++ b/vendor/github.com/hashicorp/go-getter/decompress_tar.go | |||
@@ -6,6 +6,7 @@ import ( | |||
6 | "io" | 6 | "io" |
7 | "os" | 7 | "os" |
8 | "path/filepath" | 8 | "path/filepath" |
9 | "time" | ||
9 | ) | 10 | ) |
10 | 11 | ||
11 | // untar is a shared helper for untarring an archive. The reader should provide | 12 | // untar is a shared helper for untarring an archive. The reader should provide |
@@ -14,6 +15,7 @@ func untar(input io.Reader, dst, src string, dir bool) error { | |||
14 | tarR := tar.NewReader(input) | 15 | tarR := tar.NewReader(input) |
15 | done := false | 16 | done := false |
16 | dirHdrs := []*tar.Header{} | 17 | dirHdrs := []*tar.Header{} |
18 | now := time.Now() | ||
17 | for { | 19 | for { |
18 | hdr, err := tarR.Next() | 20 | hdr, err := tarR.Next() |
19 | if err == io.EOF { | 21 | if err == io.EOF { |
@@ -95,17 +97,37 @@ func untar(input io.Reader, dst, src string, dir bool) error { | |||
95 | return err | 97 | return err |
96 | } | 98 | } |
97 | 99 | ||
98 | // Set the access and modification time | 100 | // Set the access and modification time if valid, otherwise default to current time |
99 | if err := os.Chtimes(path, hdr.AccessTime, hdr.ModTime); err != nil { | 101 | aTime := now |
102 | mTime := now | ||
103 | if hdr.AccessTime.Unix() > 0 { | ||
104 | aTime = hdr.AccessTime | ||
105 | } | ||
106 | if hdr.ModTime.Unix() > 0 { | ||
107 | mTime = hdr.ModTime | ||
108 | } | ||
109 | if err := os.Chtimes(path, aTime, mTime); err != nil { | ||
100 | return err | 110 | return err |
101 | } | 111 | } |
102 | } | 112 | } |
103 | 113 | ||
104 | // Adding a file or subdirectory changes the mtime of a directory | 114 | // Perform a final pass over extracted directories to update metadata |
105 | // We therefore wait until we've extracted everything and then set the mtime and atime attributes | ||
106 | for _, dirHdr := range dirHdrs { | 115 | for _, dirHdr := range dirHdrs { |
107 | path := filepath.Join(dst, dirHdr.Name) | 116 | path := filepath.Join(dst, dirHdr.Name) |
108 | if err := os.Chtimes(path, dirHdr.AccessTime, dirHdr.ModTime); err != nil { | 117 | // Chmod the directory since they might be created before we know the mode flags |
118 | if err := os.Chmod(path, dirHdr.FileInfo().Mode()); err != nil { | ||
119 | return err | ||
120 | } | ||
121 | // Set the mtime/atime attributes since they would have been changed during extraction | ||
122 | aTime := now | ||
123 | mTime := now | ||
124 | if dirHdr.AccessTime.Unix() > 0 { | ||
125 | aTime = dirHdr.AccessTime | ||
126 | } | ||
127 | if dirHdr.ModTime.Unix() > 0 { | ||
128 | mTime = dirHdr.ModTime | ||
129 | } | ||
130 | if err := os.Chtimes(path, aTime, mTime); err != nil { | ||
109 | return err | 131 | return err |
110 | } | 132 | } |
111 | } | 133 | } |