Skip to content

Commit

Permalink
Merge pull request #7449 from estesp/cp-7094-1.5
Browse files Browse the repository at this point in the history
[release/1.5] cherry-pick: make xattr EPERM non-fatal in createTarFile
  • Loading branch information
mxpv committed Sep 29, 2022
2 parents 2944d61 + f94332e commit b5f1e2e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion archive/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ const (
whiteoutOpaqueDir = whiteoutMetaPrefix + ".opq"

paxSchilyXattr = "SCHILY.xattr."

userXattrPrefix = "user."
)

// Apply applies a tar stream of an OCI style diff tar.
Expand Down Expand Up @@ -390,11 +392,19 @@ func createTarFile(ctx context.Context, path, extractDir string, hdr *tar.Header
if strings.HasPrefix(key, paxSchilyXattr) {
key = key[len(paxSchilyXattr):]
if err := setxattr(path, key, value); err != nil {
if errors.Is(err, syscall.EPERM) && strings.HasPrefix(key, userXattrPrefix) {
// In the user.* namespace, only regular files and directories can have extended attributes.
// See https://man7.org/linux/man-pages/man7/xattr.7.html for details.
if fi, err := os.Lstat(path); err == nil && (!fi.Mode().IsRegular() && !fi.Mode().IsDir()) {
log.G(ctx).WithError(err).Warnf("ignored xattr %s in archive", key)
continue
}
}
if errors.Is(err, syscall.ENOTSUP) {
log.G(ctx).WithError(err).Warnf("ignored xattr %s in archive", key)
continue
}
return err
return fmt.Errorf("failed to setxattr %q for key %q: %w", path, key, err)
}
}
}
Expand Down

0 comments on commit b5f1e2e

Please sign in to comment.