]> Cypherpunks repositories - gostls13.git/commit
archive/zip: fix regression when writing directories
authorJoe Tsai <joetsai@digital-static.net>
Mon, 16 Jul 2018 20:05:25 +0000 (13:05 -0700)
committerJoe Tsai <thebrokentoaster@gmail.com>
Mon, 16 Jul 2018 22:52:11 +0000 (22:52 +0000)
commit4b0c8b0136ee54e779b9eddf7ba00f6ecfeb9f6f
tree52cf2122055dbe5e7b512c866ad306ccd2df414d
parentc80897b691a5f5541e8491b29a42877aed33140c
archive/zip: fix regression when writing directories

Several adjustments:

1) When encoding the FileHeader for a directory, explicitly set all of the sizes
to zero regardless of their prior values. These values are currently populated
by FileInfoHeader as it calls os.FileInfo.Size regardless of whether the file is
a directory or not. We avoid fixing FileInfoHeader now as it is too late in the
release cycle (see #24082).

We silently adjust slightly wrong FileHeader fields as opposed to returning
an error because the CreateHeader method already does such mutations
(e.g., for UTF-8 detection, data descriptor, etc).

2) Have dirWriter.Write only return an error if some number of bytes are written.
Some code still call Write for both normal files and directories, but just pass
an empty []byte to Write for directories.

Change-Id: I85492a31356107fcf76dc89ceb00a28853754289
Reviewed-on: https://go-review.googlesource.com/124155
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/archive/zip/writer.go
src/archive/zip/writer_test.go