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,7 +512,9 @@ func createTarFile(ctx context.Context, path, extractDir string, hdr *tar.Header
} }
} }
for key, value := range hdr.Xattrs { for key, value := range hdr.PAXRecords {
if strings.HasPrefix(key, paxSchilyXattr) {
key = key[len(paxSchilyXattr):]
if err := setxattr(path, key, value); err != nil { if err := setxattr(path, key, value); err != nil {
if errors.Cause(err) == syscall.ENOTSUP { if errors.Cause(err) == syscall.ENOTSUP {
log.G(ctx).WithError(err).Warnf("ignored xattr %s in archive", key) log.G(ctx).WithError(err).Warnf("ignored xattr %s in archive", key)
@ -518,6 +523,7 @@ func createTarFile(ctx context.Context, path, extractDir string, hdr *tar.Header
return err return err
} }
} }
}
// There is no LChmod, so ignore mode for symlink. Also, this // There is no LChmod, so ignore mode for symlink. Also, this
// must happen after chown, as that can modify the file mode // must happen after chown, as that can modify the file mode