Skip to content
Open
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
Binary file modified internal/provider/archive-dir.zip
Binary file not shown.
Binary file modified internal/provider/archive-file.zip
Binary file not shown.
8 changes: 4 additions & 4 deletions internal/provider/zip_archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func (a *ZipArchiver) ArchiveFile(infilename string) error {
}
fh.Name = filepath.ToSlash(fi.Name())
fh.Method = zip.Deflate
// fh.Modified alone isn't enough when using a zero value
fh.SetModTime(time.Time{})
oldestZipSupportedModTime, _ := time.Parse(time.RFC3339, "1980-01-01T00:00:00+00:00")
fh.Modified = oldestZipSupportedModTime

if a.outputFileMode != "" {
filemode, err := strconv.ParseUint(a.outputFileMode, 0, 32)
Expand Down Expand Up @@ -144,8 +144,8 @@ func (a *ZipArchiver) ArchiveDir(indirname string, excludes []string) error {
}
fh.Name = filepath.ToSlash(relname)
fh.Method = zip.Deflate
// fh.Modified alone isn't enough when using a zero value
fh.SetModTime(time.Time{})
oldestZipSupportedModTime, _ := time.Parse(time.RFC3339, "1980-01-01T00:00:00+00:00")
fh.Modified = oldestZipSupportedModTime

if a.outputFileMode != "" {
filemode, err := strconv.ParseUint(a.outputFileMode, 0, 32)
Expand Down
17 changes: 17 additions & 0 deletions internal/provider/zip_archiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func TestZipArchiver_FileModified(t *testing.T) {
if !bytes.Equal(expectedContents, actualContents) {
t.Fatalf("zip contents do not match, potentially a modified time issue")
}

oldestZipSupportedModTime, _ := time.Parse(time.RFC3339, "1980-01-01T00:00:00+00:00")
ensureModifiedtimes(t, zipFilePath, oldestZipSupportedModTime)
}

func TestZipArchiver_Dir(t *testing.T) {
Expand Down Expand Up @@ -153,6 +156,20 @@ func TestZipArchiver_Multiple(t *testing.T) {
ensureContents(t, zipfilepath, content)
}

func ensureModifiedtimes(t *testing.T, zipfilepath string, modifiedTime time.Time) {
r, err := zip.OpenReader(zipfilepath)
if err != nil {
t.Fatalf("could not open zip file: %s", err)
}
defer r.Close()

for _, cf := range r.File {
if !cf.Modified.Equal(modifiedTime) {
t.Fatalf("Modified time does not match, got %s, want %s", cf.Modified, modifiedTime)
}
}
}

func ensureContents(t *testing.T, zipfilepath string, wants map[string][]byte) {
t.Helper()
r, err := zip.OpenReader(zipfilepath)
Expand Down