]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
ls: reinstate capability checking in more cases
authorPádraig Brady <P@draigBrady.com>
Wed, 2 Oct 2024 21:57:16 +0000 (22:57 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 2 Oct 2024 22:17:48 +0000 (23:17 +0100)
The recent commit v9.5-119-g4ce432ad8 restricted capability checking
to only files with XATTR_NAME_CAPS set.  If this is done then we need
to adjust tests/ls/no-cap.sh so that it doesn't always skip.  More
problematically XATTR_NAME_CAPS was only determined in long listing
mode, thus breaking capability coloring in short listing mode
as evidenced by the failing tests/ls/capability.sh test.

Note capability checking does have a large overhead, but we've
disabled capability checking by default anyway through the default
color configuration since v9.0-187-g6b5134770

So for these reasons revert to checking capabilities as before.

* src/ls.c (gobble_file): Check for capabilities in all modes
if enabled in color config.

src/ls.c

index 099893f864c6a459f3af233fbd4113623da20631..9f3f2140021353953fc75fc10a132464000eaf88 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -3484,6 +3484,13 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
 
       f->stat_ok = true;
 
+      /* has_capability adds around 30% runtime to 'ls --color',
+          so call it only if really needed.  Note capability coloring
+          is disabled in the default color config.  */
+      if ((type == normal || S_ISREG (f->stat.st_mode))
+          && print_with_color && is_colored (C_CAP))
+        f->has_capability = has_capability_cache (full_name, f);
+
       if (format == long_format || print_scontext)
         {
           struct aclinfo ai;
@@ -3512,14 +3519,6 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
                 error (0, ai.scontext_err, "%s", quotef (full_name));
             }
 
-          /* has_capability adds around 30% runtime to 'ls --color',
-             so call it only if really needed.  */
-          if (0 < ai.size
-              && (type == normal || S_ISREG (f->stat.st_mode))
-              && print_with_color && is_colored (C_CAP)
-              && aclinfo_has_xattr (&ai, XATTR_NAME_CAPS))
-            f->has_capability = has_capability_cache (full_name, f);
-
           f->scontext = ai.scontext;
           ai.scontext = nullptr;
           aclinfo_free (&ai);