From af8b1271ebd63c1ed9bae0e7e803c0d8a2c3e38d Mon Sep 17 00:00:00 2001 From: Mike Rosset Date: Mon, 29 Aug 2011 11:01:03 -0700 Subject: [PATCH] archive/tar: when writing tar Headers write hdr.Linkname This should allow symlinks in tar files. Where previously as far as I can see they were skipped completely. R=golang-dev, dsymonds, rsc, bradfitz, bradfitz CC=golang-dev, mike.rosset https://golang.org/cl/4973044 --- src/pkg/archive/tar/testdata/writer.tar | Bin 3072 -> 3584 bytes src/pkg/archive/tar/writer.go | 2 +- src/pkg/archive/tar/writer_test.go | 19 +++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/pkg/archive/tar/testdata/writer.tar b/src/pkg/archive/tar/testdata/writer.tar index 0358f91b98b3c72134167f4917d567f53fa1b9a2..e6d816ad0775d56d09242d6f5d1dbe56af310a32 100644 GIT binary patch delta 116 zcmZpWXpmXJ!I6`hm#tS)Q8IC1jHLk(n46n304YOrQv+lgBn1KthK6QFW@aV^hK5EA t28O0)W~K}ZMiWx_ON&bqi-0dJvABSf1ppF=0{s90 diff --git a/src/pkg/archive/tar/writer.go b/src/pkg/archive/tar/writer.go index 8673bad316..c6ce2241af 100644 --- a/src/pkg/archive/tar/writer.go +++ b/src/pkg/archive/tar/writer.go @@ -134,7 +134,7 @@ func (tw *Writer) WriteHeader(hdr *Header) os.Error { tw.numeric(s.next(12), hdr.Mtime) // 136:148 s.next(8) // chksum (148:156) s.next(1)[0] = hdr.Typeflag // 156:157 - s.next(100) // linkname (157:257) + tw.cString(s.next(100), hdr.Linkname) // linkname (157:257) copy(s.next(8), []byte("ustar\x0000")) // 257:265 tw.cString(s.next(32), hdr.Uname) // 265:297 tw.cString(s.next(32), hdr.Gname) // 297:329 diff --git a/src/pkg/archive/tar/writer_test.go b/src/pkg/archive/tar/writer_test.go index 838cb7e1fe..6cc9386882 100644 --- a/src/pkg/archive/tar/writer_test.go +++ b/src/pkg/archive/tar/writer_test.go @@ -24,6 +24,10 @@ type writerTest struct { } var writerTests = []*writerTest{ + // The writer test file was produced with this command: + // tar (GNU tar) 1.26 + // ln -s small.txt link.txt + // tar -b 1 --format=ustar -c -f writer.tar small.txt small2.txt link.txt &writerTest{ file: "testdata/writer.tar", entries: []*writerTestEntry{ @@ -55,6 +59,21 @@ var writerTests = []*writerTest{ }, contents: "Google.com\n", }, + &writerTestEntry{ + header: &Header{ + Name: "link.txt", + Mode: 0777, + Uid: 1000, + Gid: 1000, + Size: 0, + Mtime: 1314603082, + Typeflag: '2', + Linkname: "small.txt", + Uname: "strings", + Gname: "strings", + }, + // no contents + }, }, }, // The truncated test file was produced using these commands: -- 2.50.0