Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/uu/ls/src/ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1987,11 +1987,7 @@ impl PathData {
None => OnceCell::new(),
};

let security_context = if config.context {
get_security_context(config, &p_buf, must_dereference)
} else {
String::new()
};
let security_context = get_security_context(config, &p_buf, must_dereference);

Self {
md: OnceCell::new(),
Expand Down Expand Up @@ -2850,7 +2846,7 @@ fn display_item_long(
#[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))]
let is_acl_set = has_acl(item.display_name.as_os_str());
output_display.extend(display_permissions(md, true).as_bytes());
if item.security_context.len() > 1 {
if !item.security_context.is_empty() {
// GNU `ls` uses a "." character to indicate a file with a security context,
// but not other alternate access method.
output_display.extend(b".");
Expand Down Expand Up @@ -2980,7 +2976,7 @@ fn display_item_long(

output_display.extend(leading_char.as_bytes());
output_display.extend(b"?????????");
if item.security_context.len() > 1 {
if !item.security_context.is_empty() {
// GNU `ls` uses a "." character to indicate a file with a security context,
// but not other alternate access method.
output_display.extend(b".");
Expand Down
22 changes: 21 additions & 1 deletion tests/by-util/test_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4150,6 +4150,22 @@ fn test_ls_dangling_symlinks() {
}
}

#[test]
#[cfg(feature = "feat_selinux")]
fn test_ls_with_selinux_ext() {
if !uucore::selinux::is_selinux_enabled() {
println!("test skipped: Kernel has no support for SElinux context");
return;
}
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.touch("foo");

let result = scene.ucmd().args(&["-l", "foo"]).succeeds();
let line: Vec<_> = result.stdout_str().split(' ').collect();
assert!(line[0].ends_with('.'));
}

#[test]
#[cfg(feature = "feat_selinux")]
fn test_ls_context1() {
Expand Down Expand Up @@ -5344,7 +5360,11 @@ fn test_acl_display() {
// ...
// drwxr-xr-x+ 2 user group 40 Apr 21 12:44 with_acl
// drwxr-xr-x 2 user group 40 Apr 21 12:44 without_acl
let re_with_acl = Regex::new(r"[a-z-]*\+ .*with_acl").unwrap();
let re_with_acl = if uucore::selinux::is_selinux_enabled() {
Regex::new(r"[a-z-]*\. .*with_acl").unwrap()
} else {
Regex::new(r"[a-z-]*\+ .*with_acl").unwrap()
};
let re_without_acl = Regex::new(r"[a-z-]* .*without_acl").unwrap();

scene
Expand Down
Loading