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

(#14) Fix for archive checksum changing with same content #15

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions archive/zip_archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"sort"
"time"
)

type ZipArchiver struct {
Expand Down Expand Up @@ -58,6 +59,8 @@ func (a *ZipArchiver) ArchiveFile(infilename string) error {
}
fh.Name = fi.Name()
fh.Method = zip.Deflate
var mtime time.Time
fh.SetModTime(mtime)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the docs should just set Modified directly:

fh.Modified = time.Time{}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileInfoHeader uses SetModTime() which sets Modified, ModifiedTime, ModifiedDate. Updating only Modified would still result in changing checksum.

Copy link
Contributor

@paultyng paultyng Mar 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the CreateHeader method overwrites those other deprecated fields as well, it only reads Modified. But they are all basically ignored because Modified is a zero value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, you are correct, I see in the internal writing that it does actually write those out :( so much for their deprecation.


f, err := a.writer.CreateHeader(fh)
if err != nil {
Expand Down Expand Up @@ -96,6 +99,9 @@ func (a *ZipArchiver) ArchiveDir(indirname string) error {
}
fh.Name = relname
fh.Method = zip.Deflate
var mtime time.Time
fh.SetModTime(mtime)

f, err := a.writer.CreateHeader(fh)
if err != nil {
return fmt.Errorf("error creating file inside archive: %s", err)
Expand Down