Skip to content

Commit

Permalink
Merge pull request #7447 from estesp/cp-7094-1.6
Browse files Browse the repository at this point in the history
[release/1.6] cherry-pick: make xattr EPERM non-fatal in createTarFile
  • Loading branch information
mxpv committed Sep 29, 2022
2 parents 7b93a22 + 2fdfd56 commit 2cbb524
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion archive/tar.go
Expand Up @@ -120,6 +120,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 @@ -393,11 +395,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 2cbb524

Please sign in to comment.