Merge pull request #8217 from sudhackar/ls-fix

ls: follow symlinks for xattrs, fix #8216
This commit is contained in:
Sudhakar Verma 2025-06-19 13:47:25 +05:30 committed by GitHub
parent 86f0c617d8
commit c674cf1839
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 43 additions and 5 deletions

View file

@ -68,6 +68,7 @@ kibi
kibibytes
libacl
lcase
listxattr
llistxattr
lossily
lstat

View file

@ -79,7 +79,7 @@ pub fn apply_xattrs<P: AsRef<Path>>(
/// `true` if the file has extended attributes (indicating an ACL), `false` otherwise.
pub fn has_acl<P: AsRef<Path>>(file: P) -> bool {
// don't use exacl here, it is doing more getxattr call then needed
xattr::list(file).is_ok_and(|acl| {
xattr::list_deref(file).is_ok_and(|acl| {
// if we have extra attributes, we have an acl
acl.count() > 0
})

View file

@ -5716,3 +5716,40 @@ fn test_unknown_format_specifier() {
.succeeds()
.stdout_matches(&re_custom_format);
}
#[cfg(all(unix, not(target_os = "macos")))]
#[test]
fn test_acl_display_symlink() {
use std::process::Command;
let (at, mut ucmd) = at_and_ucmd!();
let dir_name = "dir";
let link_name = "link";
at.mkdir(dir_name);
// calling the command directly. xattr requires some dev packages to be installed
// and it adds a complex dependency just for a test
match Command::new("setfacl")
.args(["-d", "-m", "u:bin:rwx", &at.plus_as_string(dir_name)])
.status()
.map(|status| status.code())
{
Ok(Some(0)) => {}
Ok(_) => {
println!("test skipped: setfacl failed");
return;
}
Err(e) => {
println!("test skipped: setfacl failed with {e}");
return;
}
}
at.symlink_dir(dir_name, link_name);
let re_with_acl = Regex::new(r"[a-z-]*\+ .*link").unwrap();
ucmd.arg("-lLd")
.arg(link_name)
.succeeds()
.stdout_matches(&re_with_acl);
}

View file

@ -8,13 +8,13 @@ index 99f0563bc..f7b9e7885 100755
LS_COLORS=ca=1; export LS_COLORS
-strace -e capget ls --color=always > /dev/null 2> out || fail=1
-$EGREP 'capget\(' out || skip_ "your ls doesn't call capget"
+strace -e llistxattr ls --color=always > /dev/null 2> out || fail=1
+$EGREP 'llistxattr\(' out || skip_ "your ls doesn't call llistxattr"
+strace -e listxattr ls --color=always > /dev/null 2> out || fail=1
+$EGREP 'listxattr\(' out || skip_ "your ls doesn't call listxattr"
LS_COLORS=ca=:; export LS_COLORS
-strace -e capget ls --color=always > /dev/null 2> out || fail=1
-$EGREP 'capget\(' out && fail=1
+strace -e llistxattr ls --color=always > /dev/null 2> out || fail=1
+$EGREP 'llistxattr\(' out && fail=1
+strace -e listxattr ls --color=always > /dev/null 2> out || fail=1
+$EGREP 'listxattr\(' out && fail=1
Exit $fail