Update tar to use PAXRecords instead of Xattrs

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan 2017-11-28 17:03:14 -08:00
parent 16d00870ef
commit bc9cb25012
No known key found for this signature in database
GPG Key ID: F58C5D0A4405ACDB

View File

@ -82,6 +82,8 @@ const (
// whiteoutOpaqueDir file means directory has been made opaque - meaning // whiteoutOpaqueDir file means directory has been made opaque - meaning
// readdir calls to this directory do not follow to lower layers. // readdir calls to this directory do not follow to lower layers.
whiteoutOpaqueDir = whiteoutMetaPrefix + ".opq" whiteoutOpaqueDir = whiteoutMetaPrefix + ".opq"
paxSchilyXattr = "SCHILY.xattrs."
) )
// Apply applies a tar stream of an OCI style diff tar. // Apply applies a tar stream of an OCI style diff tar.
@ -388,9 +390,10 @@ func (cw *changeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e
if capability, err := getxattr(source, "security.capability"); err != nil { if capability, err := getxattr(source, "security.capability"); err != nil {
return errors.Wrap(err, "failed to get capabilities xattr") return errors.Wrap(err, "failed to get capabilities xattr")
} else if capability != nil { } else if capability != nil {
hdr.Xattrs = map[string]string{ if hdr.PAXRecords == nil {
"security.capability": string(capability), hdr.PAXRecords = map[string]string{}
} }
hdr.PAXRecords[paxSchilyXattr+"security.capability"] = string(capability)
} }
if err := cw.tw.WriteHeader(hdr); err != nil { if err := cw.tw.WriteHeader(hdr); err != nil {
@ -509,13 +512,16 @@ func createTarFile(ctx context.Context, path, extractDir string, hdr *tar.Header
} }
} }
for key, value := range hdr.Xattrs { for key, value := range hdr.PAXRecords {
if err := setxattr(path, key, value); err != nil { if strings.HasPrefix(key, paxSchilyXattr) {
if errors.Cause(err) == syscall.ENOTSUP { key = key[len(paxSchilyXattr):]
log.G(ctx).WithError(err).Warnf("ignored xattr %s in archive", key) if err := setxattr(path, key, value); err != nil {
continue if errors.Cause(err) == syscall.ENOTSUP {
log.G(ctx).WithError(err).Warnf("ignored xattr %s in archive", key)
continue
}
return err
} }
return err
} }
} }