Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalize all tar file timestamps to Jan 01 1980 +1 second #108

Merged
merged 1 commit into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions archive/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func WriteTarArchive(w io.Writer, srcDir string, uid, gid int) error {
}
}
header.Name = file
header.ModTime = time.Time{}
header.ModTime = time.Date(1980, time.January, 1, 0, 0, 1, 0, time.UTC)
header.Uid = uid
header.Gid = gid
header.Uname = ""
Expand Down Expand Up @@ -99,7 +99,7 @@ func writeParentDirectoryHeaders(tarDir string, tw *tar.Writer, uid int, gid int
return err
}
header.Name = parent
header.ModTime = time.Time{}
header.ModTime = time.Date(1980, time.January, 1, 0, 0, 1, 0, time.UTC)

if err := tw.WriteHeader(header); err != nil {
return err
Expand Down
20 changes: 10 additions & 10 deletions archive/tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ func testTar(t *testing.T, when spec.G, it spec.S) {
header, err := tr.Next()
h.AssertNil(t, err)
h.AssertEq(t, header.Name, "testdata")
assertModTimeZeroedOut(t, header)
assertModTimeNormalized(t, header)

header, err = tr.Next()
h.AssertNil(t, err)
h.AssertEq(t, header.Name, "testdata/dir-to-tar")
assertModTimeZeroedOut(t, header)
assertModTimeNormalized(t, header)
})

tarContains(t, "regular files", func() {
Expand All @@ -85,14 +85,14 @@ func testTar(t *testing.T, when spec.G, it spec.S) {
h.AssertEq(t, string(fileContents), "some-content")
h.AssertEq(t, header.Uid, uid)
h.AssertEq(t, header.Gid, gid)
assertModTimeZeroedOut(t, header)
assertModTimeNormalized(t, header)
})

tarContains(t, "sub directories", func() {
header, err := tr.Next()
h.AssertNil(t, err)
h.AssertEq(t, header.Name, "testdata/dir-to-tar/sub-dir")
assertModTimeZeroedOut(t, header)
assertModTimeNormalized(t, header)
})

tarContains(t, "symlinks", func() {
Expand All @@ -103,7 +103,7 @@ func testTar(t *testing.T, when spec.G, it spec.S) {
h.AssertEq(t, header.Uid, uid)
h.AssertEq(t, header.Gid, gid)
h.AssertEq(t, header.Linkname, "../some-file.txt")
assertModTimeZeroedOut(t, header)
assertModTimeNormalized(t, header)
})
})

Expand Down Expand Up @@ -132,7 +132,7 @@ func testTar(t *testing.T, when spec.G, it spec.S) {
h.AssertEq(t, header.Name, expectedDir)

assertDirectory(t, header)
assertModTimeZeroedOut(t, header)
assertModTimeNormalized(t, header)
}
})
})
Expand Down Expand Up @@ -161,7 +161,7 @@ func testTar(t *testing.T, when spec.G, it spec.S) {
h.AssertEq(t, header.Name, expectedDir)

assertDirectory(t, header)
assertModTimeZeroedOut(t, header)
assertModTimeNormalized(t, header)

}
})
Expand Down Expand Up @@ -221,10 +221,10 @@ func assertDirectory(t *testing.T, header *tar.Header) {
}
}

func assertModTimeZeroedOut(t *testing.T, header *tar.Header) {
func assertModTimeNormalized(t *testing.T, header *tar.Header) {
t.Helper()
if header.ModTime.Unix() != 0 {
t.Fatalf(`expected %s time not to be set instead: %s`, header.Name, header.ModTime.String())
if !header.ModTime.Equal(time.Date(1980, time.January, 1, 0, 0, 1, 0, time.UTC)) {
t.Fatalf(`expected %s time to be normalized, instead got: %s`, header.Name, header.ModTime.String())
}
}

Expand Down