[Docker-maint] Bug#739586: [PATCH] add debian/patches/add-tar-xattr-support.patch

Johan Euphrosine proppy at google.com
Thu Feb 20 07:56:10 UTC 2014


Package: golang
Version: 2:1.2-2
Severity: wishlist

to backport support for tar xattr from upcoming golang1.3
---
 debian/golang-src.install                  |   1 +
 debian/patches/add-tar-xattr-support.patch | 175 +++++++++++++++++++++++++++++
 debian/patches/series                      |   1 +
 debian/source/include-binaries             |   1 +
 debian/xattrs.tar                          | Bin 0 -> 5120 bytes
 5 files changed, 178 insertions(+)
 create mode 100644 debian/patches/add-tar-xattr-support.patch
 create mode 100644 debian/source/include-binaries
 create mode 100644 debian/xattrs.tar

diff --git a/debian/golang-src.install b/debian/golang-src.install
index f034ba5..726c5b4 100644
--- a/debian/golang-src.install
+++ b/debian/golang-src.install
@@ -1,2 +1,3 @@
 src /usr/share/go/
 test /usr/share/go/
+debian/xattrs.tar /usr/share/go/src/pkg/archive/tar/testdata
diff --git a/debian/patches/add-tar-xattr-support.patch b/debian/patches/add-tar-xattr-support.patch
new file mode 100644
index 0000000..904e011
--- /dev/null
+++ b/debian/patches/add-tar-xattr-support.patch
@@ -0,0 +1,175 @@
+--- a/src/pkg/archive/tar/common.go
++++ b/src/pkg/archive/tar/common.go
+@@ -57,6 +57,7 @@
+ 	Devminor   int64     // minor number of character or block device
+ 	AccessTime time.Time // access time
+ 	ChangeTime time.Time // status change time
++	Xattrs     map[string]string
+ }
+ 
+ // File name constants from the tar spec.
+@@ -189,6 +190,7 @@
+ 	paxSize     = "size"
+ 	paxUid      = "uid"
+ 	paxUname    = "uname"
++	paxXattr    = "SCHILY.xattr."
+ 	paxNone     = ""
+ )
+ 
+--- a/src/pkg/archive/tar/reader.go
++++ b/src/pkg/archive/tar/reader.go
+@@ -139,8 +139,14 @@
+ 				return err
+ 			}
+ 			hdr.Size = int64(size)
++		default:
++			if strings.HasPrefix(k, paxXattr) {
++				if hdr.Xattrs == nil {
++					hdr.Xattrs = make(map[string]string)
++				}
++				hdr.Xattrs[k[len(paxXattr):]] = v
++			}
+ 		}
+-
+ 	}
+ 	return nil
+ }
+--- a/src/pkg/archive/tar/reader_test.go
++++ b/src/pkg/archive/tar/reader_test.go
+@@ -161,6 +161,46 @@
+ 			},
+ 		},
+ 	},
++	{
++		file: "testdata/xattrs.tar",
++		headers: []*Header{
++			{
++				Name:       "small.txt",
++				Mode:       0644,
++				Uid:        1000,
++				Gid:        10,
++				Size:       5,
++				ModTime:    time.Unix(1386065770, 448252320),
++				Typeflag:   '0',
++				Uname:      "alex",
++				Gname:      "wheel",
++				AccessTime: time.Unix(1389782991, 419875220),
++				ChangeTime: time.Unix(1389782956, 794414986),
++				Xattrs: map[string]string{
++					"user.key":  "value",
++					"user.key2": "value2",
++					// Interestingly, selinux encodes the terminating null inside the xattr
++					"security.selinux": "unconfined_u:object_r:default_t:s0\x00",
++				},
++			},
++			{
++				Name:       "small2.txt",
++				Mode:       0644,
++				Uid:        1000,
++				Gid:        10,
++				Size:       11,
++				ModTime:    time.Unix(1386065770, 449252304),
++				Typeflag:   '0',
++				Uname:      "alex",
++				Gname:      "wheel",
++				AccessTime: time.Unix(1389782991, 419875220),
++				ChangeTime: time.Unix(1386065770, 449252304),
++				Xattrs: map[string]string{
++					"security.selinux": "unconfined_u:object_r:default_t:s0\x00",
++				},
++			},
++		},
++	},
+ }
+ 
+ func TestReader(t *testing.T) {
+@@ -180,7 +220,7 @@
+ 				f.Close()
+ 				continue testLoop
+ 			}
+-			if *hdr != *header {
++			if !reflect.DeepEqual(*hdr, *header) {
+ 				t.Errorf("test %d, entry %d: Incorrect header:\nhave %+v\nwant %+v",
+ 					i, j, *hdr, *header)
+ 			}
+@@ -253,7 +293,7 @@
+ 		}
+ 
+ 		// check the header
+-		if *hdr != *headers[nread] {
++		if !reflect.DeepEqual(*hdr, *headers[nread]) {
+ 			t.Errorf("Incorrect header:\nhave %+v\nwant %+v",
+ 				*hdr, headers[nread])
+ 		}
+Binary files /dev/null and b/src/pkg/archive/tar/testdata/xattrs.tar differ
+--- a/src/pkg/archive/tar/writer.go
++++ b/src/pkg/archive/tar/writer.go
+@@ -236,6 +236,12 @@
+ 		return tw.err
+ 	}
+ 
++	if allowPax {
++		for k, v := range hdr.Xattrs {
++			paxHeaders[paxXattr+k] = v
++		}
++	}
++
+ 	if len(paxHeaders) > 0 {
+ 		if !allowPax {
+ 			return errInvalidHeader
+--- a/src/pkg/archive/tar/writer_test.go
++++ b/src/pkg/archive/tar/writer_test.go
+@@ -10,6 +10,7 @@
+ 	"io"
+ 	"io/ioutil"
+ 	"os"
++	"reflect"
+ 	"strings"
+ 	"testing"
+ 	"testing/iotest"
+@@ -338,6 +339,45 @@
+ 	}
+ }
+ 
++func TestPaxXattrs(t *testing.T) {
++	xattrs := map[string]string{
++		"user.key": "value",
++	}
++
++	// Create an archive with an xattr
++	fileinfo, err := os.Stat("testdata/small.txt")
++	if err != nil {
++		t.Fatal(err)
++	}
++	hdr, err := FileInfoHeader(fileinfo, "")
++	if err != nil {
++		t.Fatalf("os.Stat: %v", err)
++	}
++	contents := "Kilts"
++	hdr.Xattrs = xattrs
++	var buf bytes.Buffer
++	writer := NewWriter(&buf)
++	if err := writer.WriteHeader(hdr); err != nil {
++		t.Fatal(err)
++	}
++	if _, err = writer.Write([]byte(contents)); err != nil {
++		t.Fatal(err)
++	}
++	if err := writer.Close(); err != nil {
++		t.Fatal(err)
++	}
++	// Test that we can get the xattrs back out of the archive.
++	reader := NewReader(&buf)
++	hdr, err = reader.Next()
++	if err != nil {
++		t.Fatal(err)
++	}
++	if !reflect.DeepEqual(hdr.Xattrs, xattrs) {
++		t.Fatalf("xattrs did not survive round trip: got %+v, want %+v",
++			hdr.Xattrs, xattrs)
++	}
++}
++
+ func TestPAXHeader(t *testing.T) {
+ 	medName := strings.Repeat("CD", 50)
+ 	longName := strings.Repeat("AB", 100)
diff --git a/debian/patches/series b/debian/patches/series
index 6da8b45..0a51bc1 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1,2 @@
 add-src-pkg-debug-elf-testdata-hello.patch
+add-tar-xattr-support.patch
diff --git a/debian/source/include-binaries b/debian/source/include-binaries
new file mode 100644
index 0000000..0222ae3
--- /dev/null
+++ b/debian/source/include-binaries
@@ -0,0 +1 @@
+debian/xattrs.tar
\ No newline at end of file
diff --git a/debian/xattrs.tar b/debian/xattrs.tar
new file mode 100644
index 0000000000000000000000000000000000000000..9701950edd1f0dc82858b7117136b37391be0b08
GIT binary patch
literal 5120
zcmeHJv2KGf5M|~o_yWg1+khiw>d;i}P^nX=$R$ooYd`|ilD{uBAv6g^kxC>6-(uu<
zHg^v_-l5r}td>fyRbC(vfcdOQq}Iq(#u+Ja9X?}Dv(|CCVoJF~09ZgF;2a!G7^%~|
zYNYoMUQ-rE=5<MfNf&^--n!;4I5LG45ME;9L at fvneeClfz=*LBI8bnFP`025LJ)!=
zMno8J0GDDfIs&<m0>KzzBJ^EKyr-Mx-NQ4gq%k=v3zee}wOxElT`HH-ei(K*xV|_}
zC{$GDvDu<R={PN`MVUrfx`|V at UX}Cg<y}Q)mCx5|BTH>oW?o>&odUrVuVHkt_w?IH
zW3PV_ at V!Jxt at A^i>Yrj(>;K=H?5X8!tJS~MYVd#a^`?|QJKb&Uduf~MfN4M7$J!Lr
zF40zZMF!9x{tqJ#0F5+;{2!=)=Knre|G(mAKU`hAc#r>!#{V(9d;sW1hxVv7 at B_zF
ze)#eKF~#1~>@WTI`#+&4`lkel_5U6!N8h^5vRAE8lqGgr9-Ul!p=H1_U>TS&1K)l2
B)fNB%

literal 0
HcmV?d00001

-- 
1.9.0.rc1.175.g0b1dcb5




More information about the Docker-maint mailing list