Skip to content

Commit

Permalink
tarsum: version the addition of xattrs
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
vbatts committed Sep 15, 2014
1 parent 448c8ec commit 0ecafb8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
20 changes: 11 additions & 9 deletions pkg/tarsum/tarsum.go
Expand Up @@ -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)
Expand All @@ -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
Expand Down
11 changes: 9 additions & 2 deletions pkg/tarsum/tarsum_test.go
Expand Up @@ -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",
Expand Down

0 comments on commit 0ecafb8

Please sign in to comment.