Skip to content

Commit 68a55fe

Browse files
committed
make xattr EPERM non-fatal in createTarFile
Signed-off-by: Ye Sijun <[email protected]>
1 parent a43dfdf commit 68a55fe

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

archive/tar.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ const (
120120
whiteoutOpaqueDir = whiteoutMetaPrefix + ".opq"
121121

122122
paxSchilyXattr = "SCHILY.xattr."
123+
124+
userXattrPrefix = "user."
123125
)
124126

125127
// Apply applies a tar stream of an OCI style diff tar.
@@ -393,11 +395,19 @@ func createTarFile(ctx context.Context, path, extractDir string, hdr *tar.Header
393395
if strings.HasPrefix(key, paxSchilyXattr) {
394396
key = key[len(paxSchilyXattr):]
395397
if err := setxattr(path, key, value); err != nil {
398+
if errors.Is(err, syscall.EPERM) && strings.HasPrefix(key, userXattrPrefix) {
399+
// In the user.* namespace, only regular files and directories can have extended attributes.
400+
// See https://man7.org/linux/man-pages/man7/xattr.7.html for details.
401+
if fi, err := os.Lstat(path); err == nil && (!fi.Mode().IsRegular() && !fi.Mode().IsDir()) {
402+
log.G(ctx).WithError(err).Warnf("ignored xattr %s in archive", key)
403+
continue
404+
}
405+
}
396406
if errors.Is(err, syscall.ENOTSUP) {
397407
log.G(ctx).WithError(err).Warnf("ignored xattr %s in archive", key)
398408
continue
399409
}
400-
return err
410+
return fmt.Errorf("failed to setxattr %q for key %q: %w", path, key, err)
401411
}
402412
}
403413
}

0 commit comments

Comments
 (0)