Commit 52ccdf35 authored by David Symonds's avatar David Symonds

Add support for v7 tar.

R=rsc
APPROVED=rsc
DELTA=32  (26 added, 4 deleted, 2 changed)
OCL=31172
CL=31242
parent 2acbc371
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// The tar package implements access to tar archives. // The tar package implements access to tar archives.
// It aims to cover most of the variations, including those produced // It aims to cover most of the variations, including those produced
// by GNU and BSD tars (not yet started). // by GNU and BSD tars.
// //
// References: // References:
// http://www.freebsd.org/cgi/man.cgi?query=tar&sektion=5 // http://www.freebsd.org/cgi/man.cgi?query=tar&sektion=5
...@@ -12,8 +12,7 @@ ...@@ -12,8 +12,7 @@
package tar package tar
// TODO(dsymonds): // TODO(dsymonds):
// - Make it seekable. // - pax extensions
// - Extensions.
import ( import (
"bufio"; "bufio";
...@@ -211,9 +210,6 @@ func (tr *Reader) readHeader() *Header { ...@@ -211,9 +210,6 @@ func (tr *Reader) readHeader() *Header {
hdr := new(Header); hdr := new(Header);
s := slicer(header); s := slicer(header);
// TODO(dsymonds): The format of the header depends on the value of magic (hdr[257:262]),
// so use that value to do the correct parsing below.
hdr.Name = cString(s.next(100)); hdr.Name = cString(s.next(100));
hdr.Mode = tr.octal(s.next(8)); hdr.Mode = tr.octal(s.next(8));
hdr.Uid = tr.octal(s.next(8)); hdr.Uid = tr.octal(s.next(8));
...@@ -225,6 +221,8 @@ func (tr *Reader) readHeader() *Header { ...@@ -225,6 +221,8 @@ func (tr *Reader) readHeader() *Header {
hdr.Linkname = cString(s.next(100)); hdr.Linkname = cString(s.next(100));
// The remainder of the header depends on the value of magic. // The remainder of the header depends on the value of magic.
// The original (v7) version of tar had no explicit magic field,
// so its magic bytes, like the rest of the block, are NULs.
magic := string(s.next(8)); // contains version field as well. magic := string(s.next(8)); // contains version field as well.
var format string; var format string;
switch magic { switch magic {
......
...@@ -79,6 +79,29 @@ var untarTests = []*untarTest{ ...@@ -79,6 +79,29 @@ var untarTests = []*untarTest{
}, },
}, },
}, },
&untarTest{
file: "testdata/v7.tar",
headers: []*Header{
&Header{
Name: "small.txt",
Mode: 0640,
Uid: 73025,
Gid: 5000,
Size: 5,
Mtime: 1246508266,
Typeflag: '\x00',
},
&Header{
Name: "small2.txt",
Mode: 0640,
Uid: 73025,
Gid: 5000,
Size: 11,
Mtime: 1245217492,
Typeflag: '\x00',
},
},
},
}; };
func TestAll(t *testing.T) { func TestAll(t *testing.T) {
......
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