Skip to content
This repository was archived by the owner on Mar 29, 2023. It is now read-only.

Commit 544b04d

Browse files
authored
Merge pull request #41 from ipfs/fix/tar-time-rounding
fix: round timestamps down by truncating them to seconds
2 parents dffbf27 + 3dadb7b commit 544b04d

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

tarwriter.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func writeDirHeader(w *tar.Writer, fpath string) error {
7474
Name: fpath,
7575
Typeflag: tar.TypeDir,
7676
Mode: 0777,
77-
ModTime: time.Now(),
77+
ModTime: time.Now().Truncate(time.Second),
7878
// TODO: set mode, dates, etc. when added to unixFS
7979
})
8080
}
@@ -85,7 +85,7 @@ func writeFileHeader(w *tar.Writer, fpath string, size uint64) error {
8585
Size: int64(size),
8686
Typeflag: tar.TypeReg,
8787
Mode: 0644,
88-
ModTime: time.Now(),
88+
ModTime: time.Now().Truncate(time.Second),
8989
// TODO: set mode, dates, etc. when added to unixFS
9090
})
9191
}

tarwriter_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"archive/tar"
55
"io"
66
"testing"
7+
"time"
78
)
89

910
func TestTarWriter(t *testing.T) {
@@ -42,6 +43,10 @@ func TestTarWriter(t *testing.T) {
4243
if cur.Size != size {
4344
t.Errorf("got wrong size: %d != %d", cur.Size, size)
4445
}
46+
now := time.Now()
47+
if cur.ModTime.After(now) {
48+
t.Errorf("wrote timestamp in the future: %s (now) < %s", now, cur.ModTime)
49+
}
4550
}
4651

4752
if cur, err = tr.Next(); err != nil {

0 commit comments

Comments
 (0)