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

Commit

Permalink
Merge pull request #41 from ipfs/fix/tar-time-rounding
Browse files Browse the repository at this point in the history
fix: round timestamps down by truncating them to seconds
  • Loading branch information
Stebalien authored Sep 9, 2021
2 parents dffbf27 + 3dadb7b commit 544b04d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tarwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func writeDirHeader(w *tar.Writer, fpath string) error {
Name: fpath,
Typeflag: tar.TypeDir,
Mode: 0777,
ModTime: time.Now(),
ModTime: time.Now().Truncate(time.Second),
// TODO: set mode, dates, etc. when added to unixFS
})
}
Expand All @@ -85,7 +85,7 @@ func writeFileHeader(w *tar.Writer, fpath string, size uint64) error {
Size: int64(size),
Typeflag: tar.TypeReg,
Mode: 0644,
ModTime: time.Now(),
ModTime: time.Now().Truncate(time.Second),
// TODO: set mode, dates, etc. when added to unixFS
})
}
Expand Down
5 changes: 5 additions & 0 deletions tarwriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"archive/tar"
"io"
"testing"
"time"
)

func TestTarWriter(t *testing.T) {
Expand Down Expand Up @@ -42,6 +43,10 @@ func TestTarWriter(t *testing.T) {
if cur.Size != size {
t.Errorf("got wrong size: %d != %d", cur.Size, size)
}
now := time.Now()
if cur.ModTime.After(now) {
t.Errorf("wrote timestamp in the future: %s (now) < %s", now, cur.ModTime)
}
}

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

0 comments on commit 544b04d

Please sign in to comment.