aboutsummaryrefslogtreecommitdiff
path: root/src/archive
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2017-11-15 12:38:26 -0800
committerRuss Cox <rsc@golang.org>2017-11-29 16:28:13 +0000
commitd85a3535fe9b8c85f8876fab7f8ea0c984ec38e9 (patch)
tree11d8679837f73a110d1cf6c5ab287bbbd96478f5 /src/archive
parentbe67e269b4a4161f4276e2619c5019a26e94541c (diff)
downloadgo-d85a3535fe9b8c85f8876fab7f8ea0c984ec38e9.tar.gz
go-d85a3535fe9b8c85f8876fab7f8ea0c984ec38e9.zip
archive/zip: preserve old FileHeader.ModTime behavior
In order to avoid a regression where the date of the ModTime method changed behavior, simply preserve the old behavior of determining the date based on the legacy fields. This ensures that anyone relying on ModTime before Go1.10 will have the exact same behavior as before. New users should use FileHeader.Modified instead. We keep the UTC coersion logic in SetModTime since some users manually compute timezone offsets in order to have precise control over the MS-DOS time field. Fixes #22738 Change-Id: Ib18b6ebd863bcf645748e083357dce9bc788cdba Reviewed-on: https://go-review.googlesource.com/78031 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/archive')
-rw-r--r--src/archive/zip/struct.go8
-rw-r--r--src/archive/zip/writer.go2
2 files changed, 3 insertions, 7 deletions
diff --git a/src/archive/zip/struct.go b/src/archive/zip/struct.go
index 63fa0b3b4d..f613ebdc34 100644
--- a/src/archive/zip/struct.go
+++ b/src/archive/zip/struct.go
@@ -228,15 +228,11 @@ func timeToMsDosTime(t time.Time) (fDate uint16, fTime uint16) {
return
}
-// ModTime returns the modification time in UTC.
-// This returns Modified if non-zero, otherwise it computes the timestamp
-// from the legacy ModifiedDate and ModifiedTime fields.
+// ModTime returns the modification time in UTC using the legacy
+// ModifiedDate and ModifiedTime fields.
//
// Deprecated: Use Modified instead.
func (h *FileHeader) ModTime() time.Time {
- if !h.Modified.IsZero() {
- return h.Modified.UTC() // Convert to UTC for compatibility
- }
return msDosTimeToTime(h.ModifiedDate, h.ModifiedTime)
}
diff --git a/src/archive/zip/writer.go b/src/archive/zip/writer.go
index bcab212d40..14a5ee48c1 100644
--- a/src/archive/zip/writer.go
+++ b/src/archive/zip/writer.go
@@ -310,7 +310,7 @@ func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error) {
// This format happens to be identical for both local and central header
// if modification time is the only timestamp being encoded.
var mbuf [9]byte // 2*SizeOf(uint16) + SizeOf(uint8) + SizeOf(uint32)
- mt := uint32(fh.ModTime().Unix())
+ mt := uint32(fh.Modified.Unix())
eb := writeBuf(mbuf[:])
eb.uint16(extTimeExtraID)
eb.uint16(5) // Size: SizeOf(uint8) + SizeOf(uint32)