]> Cypherpunks repositories - gostls13.git/commit
archive/tar,zip: implement the os.FileInfo interface correctly.
authorRob Pike <r@golang.org>
Tue, 20 Aug 2013 22:29:41 +0000 (08:29 +1000)
committerRob Pike <r@golang.org>
Tue, 20 Aug 2013 22:29:41 +0000 (08:29 +1000)
commit9364868a07e9fe1cc58d963e4523bc5883201206
tree032c3733b5e88b13d35c267d06b0895066ea84d2
parentec89171ef92ffb7996a510239537473179265fc8
archive/tar,zip: implement the os.FileInfo interface correctly.
This is potentially an API-breaking change, but it is an important bug fix.

The CL https://golang.org/cl/7305072/ added stuff to make
the tar file look more like a file system internally, including providing an
implementation of os.FileInfo for the file headers within the archive.
But the code is incorrect because FileInfo.Name is supposed to return
the base name only; this implementation returns the full path. A round
trip test added in the same shows this in action, as the slashes are
preserved as we create a header using the local implementation of
FileInfo.

The CL here changes the behavior of the tar (and zip) FileInfo to honor
the Go spec for that interface. It also clarifies that the FileInfoHeader
function, which takes a FileInfo as an argument, will therefore create
a header with only the base name of the file recorded, and that
subsequent adjustment may be necessary.

There may be code out there that depends on the broken behavior.
We can call out the risk in the release notes.

Fixes #6180.

R=golang-dev, dsymonds, adg, bradfitz
CC=golang-dev
https://golang.org/cl/13118043
src/pkg/archive/tar/common.go
src/pkg/archive/tar/tar_test.go
src/pkg/archive/zip/struct.go