Skip to content

Commit

Permalink
workaround the test
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Jan 9, 2024
1 parent 684b5b3 commit 91eac5e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 30 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/CICD.yml
Expand Up @@ -612,9 +612,18 @@ jobs:
run: |
## Install/setup prerequisites
case '${{ matrix.job.target }}' in
arm-unknown-linux-gnueabihf) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;;
aarch64-unknown-linux-*) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;;
*-redox*) sudo apt-get -y update ; sudo apt-get -y install fuse3 libfuse-dev ;;
arm-unknown-linux-gnueabihf)
sudo apt-get -y update
sudo apt-get -y install gcc-arm-linux-gnueabihf
;;
aarch64-unknown-linux-*)
sudo apt-get -y update
sudo apt-get -y install gcc-aarch64-linux-gnu
;;
*-redox*)
sudo apt-get -y update
sudo apt-get -y install fuse3 libfuse-dev
;;
esac
case '${{ matrix.job.os }}' in
macos-latest) brew install coreutils ;; # needed for testing
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Expand Up @@ -492,7 +492,6 @@ uucore = { workspace = true, features = ["entries", "process", "signals"] }
walkdir = { workspace = true }
hex-literal = "0.4.1"
rstest = { workspace = true }
exacl = { workspace = true }

[target.'cfg(any(target_os = "linux", target_os = "android"))'.dev-dependencies]
procfs = { version = "0.16", default-features = false }
Expand Down
19 changes: 11 additions & 8 deletions src/uu/ls/src/ls.rs
Expand Up @@ -3,7 +3,7 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

// spell-checker:ignore (ToDO) somegroup nlink tabsize dired subdired dtype colorterm
// spell-checker:ignore (ToDO) somegroup nlink tabsize dired subdired dtype colorterm getxattr

use clap::{
builder::{NonEmptyStringValueParser, ValueParser},
Expand Down Expand Up @@ -2621,18 +2621,16 @@ fn display_grid(
Ok(())
}

fn file_has_acl_cache<P: AsRef<Path>>(file: P) -> bool {
#[cfg(unix)]
fn file_has_acl<P: AsRef<Path>>(file: P) -> bool {
// don't use exacl here, it is doing more getxattr call then needed
#[cfg(unix)]
match xattr::list(file) {
Ok(acl) => {
// no extra perms
return acl.count() > 0;
acl.count() > 0
}
Err(_) => return false,
Err(_) => false,
}
#[cfg(not(unix))]
return false;
}

/// This writes to the BufWriter out a single string of the output of `ls -l`.
Expand Down Expand Up @@ -2678,6 +2676,11 @@ fn display_item_long(
output_display += " ";
}
if let Some(md) = item.get_metadata(out) {
#[cfg(not(all(unix, not(target_os = "macos"))))]
// TODO: See how Mac should work here
let is_acl_set = false;

Check warning on line 2681 in src/uu/ls/src/ls.rs

View check run for this annotation

Codecov / codecov/patch

src/uu/ls/src/ls.rs#L2681

Added line #L2681 was not covered by tests
#[cfg(all(unix, not(target_os = "macos")))]
let is_acl_set = file_has_acl(item.display_name.as_os_str());
write!(
output_display,
"{}{}{} {}",
Expand All @@ -2689,7 +2692,7 @@ fn display_item_long(
} else {
""
},
if file_has_acl_cache(item.display_name.as_os_str()) {
if is_acl_set {
// if acl has been set, we display a "+" at the end of the file permissions
"+"
} else {
Expand Down
36 changes: 19 additions & 17 deletions tests/by-util/test_ls.rs
Expand Up @@ -4294,31 +4294,33 @@ fn test_term_colorterm() {
);
}

#[cfg(target_os = "linux")]
#[cfg(all(unix, not(target_os = "macos")))]
#[test]
fn test_acl_display() {
use crate::common::util::whoami;
use exacl::setfacl;
use exacl::{AclEntry, Perm};

let username = whoami();
use std::process::Command;

let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let file_name = "a42";
at.make_file(file_name);
at.mkdir(file_name);

let file_path = at.plus_as_string(file_name);

let entries = vec![
AclEntry::allow_user("", Perm::READ | Perm::WRITE, None),
AclEntry::allow_group("", Perm::READ, None),
AclEntry::allow_other(Perm::empty(), None),
AclEntry::allow_user(&username, Perm::READ | Perm::WRITE, None),
];
match setfacl(&[&file_path], &entries, None) {
Ok(_) => println!("Permissions set successfully."),
Err(e) => eprintln!("Failed to set permissions: {}", e),
// 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", "group::rwx", &file_path])
.status()
.map(|status| status.code())
{
Ok(Some(0)) => {}
Ok(_) => {
println!("test skipped: setfacl failed");

Check warning on line 4317 in tests/by-util/test_ls.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_ls.rs#L4317

Added line #L4317 was not covered by tests
return;
}
Err(e) => {
println!("test skipped: setfacl failed with {}", e);

Check warning on line 4321 in tests/by-util/test_ls.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_ls.rs#L4320-L4321

Added lines #L4320 - L4321 were not covered by tests
return;
}

Check warning on line 4323 in tests/by-util/test_ls.rs

View check run for this annotation

Codecov / codecov/patch

tests/by-util/test_ls.rs#L4323

Added line #L4323 was not covered by tests
}

scene
Expand Down

0 comments on commit 91eac5e

Please sign in to comment.