Skip to content

Commit

Permalink
various fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
matrixhead committed May 18, 2024
1 parent a83a8ad commit 9b5be24
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
9 changes: 7 additions & 2 deletions tests/by-util/test_chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ fn test_chmod_recursive() {
at.mkdir("a/b");
at.mkdir("a/b/c");
at.mkdir("z");

// create expected permissions by removing read bits and write bits to the current perms
let a_perms_expected = (at.metadata("a").permissions().mode() & !0o444) | 0o222;
let z_perms_expected = (at.metadata("z").permissions().mode() & !0o444) | 0o222;

make_file(&at.plus_as_string("a/a"), 0o100444);
make_file(&at.plus_as_string("a/b/b"), 0o100444);
make_file(&at.plus_as_string("a/b/c/c"), 0o100444);
Expand All @@ -358,8 +363,8 @@ fn test_chmod_recursive() {
assert_eq!(at.metadata("a/b/b").permissions().mode(), 0o100444);
assert_eq!(at.metadata("a/b/c/c").permissions().mode(), 0o100444);
println!("mode {:o}", at.metadata("a").permissions().mode());
assert_eq!(at.metadata("a").permissions().mode(), 0o40333);
assert_eq!(at.metadata("z").permissions().mode(), 0o40333);
assert_eq!(at.metadata("a").permissions().mode(), a_perms_expected);
assert_eq!(at.metadata("z").permissions().mode(), z_perms_expected);
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions tests/by-util/test_cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2542,15 +2542,15 @@ fn test_no_preserve_mode() {
let (at, mut ucmd) = at_and_ucmd!();
at.touch("file");
set_permissions(at.plus("file"), PermissionsExt::from_mode(PERMS_ALL)).unwrap();
let umask = 0o022;
let umask: u16 = 0o022;
ucmd.arg("file")
.arg("dest")
.umask(umask)
.umask(umask as libc::mode_t)
.succeeds()
.no_stderr()
.no_stdout();
// remove sticky bit, setuid and setgid bit; apply umask
let expected_perms = PERMS_ALL & !0o7000 & !umask;
let expected_perms = PERMS_ALL & !0o7000 & !umask as u32;
assert_eq!(
at.plus("dest").metadata().unwrap().mode() & 0o7777,
expected_perms
Expand Down
5 changes: 1 addition & 4 deletions tests/by-util/test_mkdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ fn test_mkdir_parent_mode_check_existing_parent() {

assert!(at.dir_exists("a"));
// parent dirs that already exist do not get their permissions modified
assert_eq!(
at.metadata("a").permissions().mode() as mode_t,
parent_a_perms
);
assert_eq!(at.metadata("a").permissions().mode(), parent_a_perms);
assert!(at.dir_exists("a/b"));
assert_eq!(
at.metadata("a/b").permissions().mode() as mode_t,
Expand Down
13 changes: 12 additions & 1 deletion tests/common/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3901,7 +3901,18 @@ mod tests {
let p_umask = get_umask();
// make sure we are not testing against the same umask
let c_umask = if p_umask == 0o002 { 0o007 } else { 0o002 };
let expected = if p_umask == 0o002 { "0007\n" } else { "0002\n" };
let expected = if cfg!(target_os = "android") {
if p_umask == 0o002 {
"007\n"
} else {
"002\n"
}
} else if p_umask == 0o002 {
"0007\n"

Check warning on line 3911 in tests/common/util.rs

View check run for this annotation

Codecov / codecov/patch

tests/common/util.rs#L3911

Added line #L3911 was not covered by tests
} else {
"0002\n"
};

let ts = TestScenario::new("util");
ts.cmd("sh")
.args(&["-c", "umask"])
Expand Down

0 comments on commit 9b5be24

Please sign in to comment.