Update go-getter to pick up file accesstime fix

This commit is contained in:
Preetha Appan
2018-04-25 17:44:25 -05:00
committed by Alex Dadgar
parent f595e9fbfb
commit 0559dfb9ee
3 changed files with 2094 additions and 358 deletions

View File

@@ -6,6 +6,7 @@ import (
"io"
"os"
"path/filepath"
"time"
)
// 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 {
tarR := tar.NewReader(input)
done := false
dirHdrs := []*tar.Header{}
now := time.Now()
for {
hdr, err := tarR.Next()
if err == io.EOF {
@@ -95,8 +97,16 @@ func untar(input io.Reader, dst, src string, dir bool) error {
return err
}
// Set the access and modification time
if err := os.Chtimes(path, hdr.AccessTime, hdr.ModTime); err != nil {
// Set the access and modification time if valid, otherwise default to current time
aTime := now
mTime := now
if hdr.AccessTime.Unix() > 0 {
aTime = hdr.AccessTime
}
if hdr.ModTime.Unix() > 0 {
mTime = hdr.ModTime
}
if err := os.Chtimes(path, aTime, mTime); err != nil {
return err
}
}
@@ -109,7 +119,15 @@ func untar(input io.Reader, dst, src string, dir bool) error {
return err
}
// Set the mtime/atime attributes since they would have been changed during extraction
if err := os.Chtimes(path, dirHdr.AccessTime, dirHdr.ModTime); err != nil {
aTime := now
mTime := now
if dirHdr.AccessTime.Unix() > 0 {
aTime = dirHdr.AccessTime
}
if dirHdr.ModTime.Unix() > 0 {
mTime = dirHdr.ModTime
}
if err := os.Chtimes(path, aTime, mTime); err != nil {
return err
}
}

View File

@@ -72,9 +72,13 @@ func TestDecompressor(t testing.T, d Decompressor, cases []TestDecompressCase) {
if tc.Mtime != nil {
actual := fi.ModTime()
expected := *tc.Mtime
if actual != expected {
t.Fatalf("err %s: expected mtime '%s' for %s, got '%s'", tc.Input, expected.String(), dst, actual.String())
if tc.Mtime.Unix() > 0 {
expected := *tc.Mtime
if actual != expected {
t.Fatalf("err %s: expected mtime '%s' for %s, got '%s'", tc.Input, expected.String(), dst, actual.String())
}
} else if actual.Unix() <= 0 {
t.Fatalf("err %s: expected mtime to be > 0, got '%s'", actual.String())
}
}
@@ -103,10 +107,15 @@ func TestDecompressor(t testing.T, d Decompressor, cases []TestDecompressCase) {
t.Fatalf("err: %s", err)
}
actual := fi.ModTime()
expected := *tc.Mtime
if actual != expected {
t.Fatalf("err %s: expected mtime '%s' for %s, got '%s'", tc.Input, expected.String(), path, actual.String())
if tc.Mtime.Unix() > 0 {
expected := *tc.Mtime
if actual != expected {
t.Fatalf("err %s: expected mtime '%s' for %s, got '%s'", tc.Input, expected.String(), path, actual.String())
}
} else if actual.Unix() < 0 {
t.Fatalf("err %s: expected mtime to be > 0, got '%s'", actual.String())
}
}
}
}()

2407
vendor/vendor.json vendored

File diff suppressed because it is too large Load Diff