1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

tarsum: version the addition of xattrs

Now that TarSum can be versioned, move the addition of xattr headers in
to the next version of TarSum

Signed-off-by: Vincent Batts <vbatts@redhat.com>
This commit is contained in:
Vincent Batts 2014-09-15 16:08:05 -04:00
parent 448c8ecb0f
commit 0ecafb8a69
2 changed files with 20 additions and 11 deletions

View file

@ -81,7 +81,7 @@ func (ts tarSum) selectHeaders(h *tar.Header, v Version) (set [][2]string) {
{"devmajor", strconv.Itoa(int(h.Devmajor))},
{"devminor", strconv.Itoa(int(h.Devminor))},
} {
if v == VersionDev && elem[0] == "mtime" {
if v >= VersionDev && elem[0] == "mtime" {
continue
}
set = append(set, elem)
@ -97,14 +97,16 @@ func (ts *tarSum) encodeHeader(h *tar.Header) error {
}
// include the additional pax headers, from an ordered list
var keys []string
for k := range h.Xattrs {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
if _, err := ts.h.Write([]byte(k + h.Xattrs[k])); err != nil {
return err
if ts.Version() >= VersionDev {
var keys []string
for k := range h.Xattrs {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
if _, err := ts.h.Write([]byte(k + h.Xattrs[k])); err != nil {
return err
}
}
}
return nil

View file

@ -38,10 +38,17 @@ var testLayers = []testLayer{
gzip: true,
tarsum: "tarsum+sha256:e58fcf7418d4390dec8e8fb69d88c06ec07039d651fedd3aa72af9972e7d046b"},
{
// Tests existing version of TarSum when xattrs are present
filename: "testdata/xattr/layer.tar",
jsonfile: "testdata/xattr/json",
// without xattr support, this layer produces "tarsum+sha256:e86f81a4d552f13039b1396ed03ca968ea9717581f9577ef1876ea6ff9b38c98"
tarsum: "tarsum+sha256:eadcd9c55164e2a942ea67f781abbf645ee55d36e173c34de8a36d4d69d3021c"},
version: Version0,
tarsum: "tarsum+sha256:e86f81a4d552f13039b1396ed03ca968ea9717581f9577ef1876ea6ff9b38c98"},
{
// Tests next version of TarSum when xattrs are present
filename: "testdata/xattr/layer.tar",
jsonfile: "testdata/xattr/json",
version: VersionDev,
tarsum: "tarsum.dev+sha256:6235cd3a2afb7501bac541772a3d61a3634e95bc90bb39a4676e2cb98d08390d"},
{
filename: "testdata/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/layer.tar",
jsonfile: "testdata/511136ea3c5a64f264b78b5433614aec563103b4d4702f3ba7d4d2698e22c158/json",