Skip to content

Commit ffc6eb0

Browse files
committed
ls: Don't call the capabilites features of the system when passed an empty ca=
in LS_COLORS In parallel, in the GNU test, adjust the GNU tests as we don't use libcap but xattr instead.
1 parent 9a97c18 commit ffc6eb0

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

.vscode/cspell.dictionaries/jargon.wordlist.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ bytewise
1010
canonicalization
1111
canonicalize
1212
canonicalizing
13+
capget
1314
codepoint
1415
codepoints
1516
codegen
@@ -65,6 +66,7 @@ kibi
6566
kibibytes
6667
libacl
6768
lcase
69+
llistxattr
6870
lossily
6971
lstat
7072
mebi
@@ -108,6 +110,7 @@ seedable
108110
semver
109111
semiprime
110112
semiprimes
113+
setcap
111114
setfacl
112115
shortcode
113116
shortcodes

src/uu/ls/src/colors.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,23 @@ pub(crate) fn color_name(
156156
target_symlink: Option<&PathData>,
157157
wrap: bool,
158158
) -> String {
159-
#[cfg(any(not(unix), target_os = "android", target_os = "macos"))]
160-
let has_capabilities = false;
161-
#[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))]
162159
// Check if the file has capabilities
163-
let has_capabilities = uucore::fsxattr::has_acl(path.p_buf.as_path());
164-
165-
// If the file has capabilities, use a specific style for `ca` (capabilities)
166-
if has_capabilities {
167-
if let Some(style) = style_manager
160+
#[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))]
161+
{
162+
// Skip checking capabilities if LS_COLORS=ca=:
163+
let capabilities = style_manager
168164
.colors
169-
.style_for_indicator(Indicator::Capabilities)
170-
{
171-
return style_manager.apply_style(Some(style), name, wrap);
165+
.style_for_indicator(Indicator::Capabilities);
166+
167+
let has_capabilities = if capabilities.is_none() {
168+
false
169+
} else {
170+
uucore::fsxattr::has_acl(path.p_buf.as_path())
171+
};
172+
173+
// If the file has capabilities, use a specific style for `ca` (capabilities)
174+
if has_capabilities {
175+
return style_manager.apply_style(capabilities, name, wrap);
172176
}
173177
}
174178

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/tests/ls/no-cap.sh b/tests/ls/no-cap.sh
2+
index 3d84c74ff..d1f60e70a 100755
3+
--- a/tests/ls/no-cap.sh
4+
+++ b/tests/ls/no-cap.sh
5+
@@ -21,13 +21,13 @@ print_ver_ ls
6+
require_strace_ capget
7+
8+
LS_COLORS=ca=1; export LS_COLORS
9+
-strace -e capget ls --color=always > /dev/null 2> out || fail=1
10+
-$EGREP 'capget\(' out || skip_ "your ls doesn't call capget"
11+
+strace -e llistxattr ls --color=always > /dev/null 2> out || fail=1
12+
+$EGREP 'llistxattr\(' out || skip_ "your ls doesn't call llistxattr"
13+
14+
rm -f out
15+
16+
LS_COLORS=ca=:; export LS_COLORS
17+
-strace -e capget ls --color=always > /dev/null 2> out || fail=1
18+
-$EGREP 'capget\(' out && fail=1
19+
+strace -e llistxattr ls --color=always > /dev/null 2> out || fail=1
20+
+$EGREP 'llistxattr\(' out && fail=1
21+
22+
Exit $fail

0 commit comments

Comments
 (0)