From 647a8b8cf9184b12e15cca3b62b8647d8d8447e0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?=
Date: Wed, 2 Oct 2024 22:57:16 +0100 Subject: [PATCH] ls: reinstate capability checking in more cases 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 | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/ls.c b/src/ls.c index 099893f864..9f3f214002 100644 --- 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); -- 2.47.2