Skip to content

Commit

Permalink
Set archive modification time to current time
Browse files Browse the repository at this point in the history
"github.com/klauspost/compress/gzip".Writer doesn't support omitting
the modification time in the header of a gzip stream.
  • Loading branch information
hansmi committed Nov 23, 2022
1 parent 275fa7c commit 4bcd813
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/snapshotstream/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func (s *Stream) writeTo(w io.Writer) (err error) {
gzipWriter := gzip.NewWriter(w)
gzipWriter.Header.Name = strings.TrimSuffix(filepath.Base(s.Filename), filepath.Ext(s.Filename))
gzipWriter.Header.Comment = fmt.Sprintf("Prometheus snapshot %s", s.name)
gzipWriter.Header.ModTime = time.Now()

defer multierr.AppendInvoke(&err, multierr.Close(gzipWriter))

Expand Down
2 changes: 1 addition & 1 deletion internal/snapshotstream/stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestStream(t *testing.T) {
t.Errorf("gzip.NewReader() failed: %v", err)
}

if diff := cmp.Diff(tc.wantGzipHeader, gzReader.Header, cmpopts.IgnoreFields(gzip.Header{}, "OS")); diff != "" {
if diff := cmp.Diff(tc.wantGzipHeader, gzReader.Header, cmpopts.IgnoreFields(gzip.Header{}, "OS", "ModTime")); diff != "" {
t.Errorf("Gzip header diff (-want +got):\n%s", diff)
}

Expand Down

0 comments on commit 4bcd813

Please sign in to comment.