Commit 17fa5a7c authored by Joe Tsai's avatar Joe Tsai Committed by Joe Tsai

archive/tar: roundtrip reading device numbers

Both GNU and BSD tar do not care if the devmajor and devminor values are
set on entries (like regular files) that aren't character or block devices.

While this is non-sensible, it is more consistent with the Writer to actually
read these fields always. In a vast majority of the cases these will still
be zero. In the rare situation where someone actually cares about these,
at least information was not silently lost.

Change-Id: I6e4ba01cd897a1b13c28b1837e102a4fdeb420ba
Reviewed-on: https://go-review.googlesource.com/55572Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 0b06929b
......@@ -468,10 +468,8 @@ func (tr *Reader) readHeader() (*Header, *block, error) {
ustar := tr.blk.USTAR()
hdr.Uname = p.parseString(ustar.UserName())
hdr.Gname = p.parseString(ustar.GroupName())
if hdr.Typeflag == TypeChar || hdr.Typeflag == TypeBlock {
hdr.Devmajor = p.parseNumeric(ustar.DevMajor())
hdr.Devminor = p.parseNumeric(ustar.DevMinor())
}
var prefix string
switch format {
......
......@@ -384,6 +384,17 @@ func TestReader(t *testing.T) {
Uid: 010000000,
ModTime: time.Unix(0, 0),
}},
}, {
// USTAR archive with a regular entry with non-zero device numbers.
file: "testdata/ustar-file-devs.tar",
headers: []*Header{{
Name: "file",
Mode: 0644,
Typeflag: '0',
ModTime: time.Unix(0, 0),
Devmajor: 1,
Devminor: 1,
}},
}}
for _, v := range vectors {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment