From 4384dafed65231effd2c6cc4642279aeec2ced23 Mon Sep 17 00:00:00 2001 From: mhead Date: Thu, 16 May 2024 14:24:51 +0530 Subject: [PATCH 1/7] util: added umask manipulation --- tests/common/util.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/tests/common/util.rs b/tests/common/util.rs index ebf95f4b422..4a97a4aa004 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -1253,6 +1253,8 @@ pub struct UCommand { #[cfg(unix)] terminal_simulation: Option, tmpd: Option>, // drop last + #[cfg(unix)] + umask: Option, } impl UCommand { @@ -1418,6 +1420,13 @@ impl UCommand { self } + #[cfg(unix)] + /// The umask is a value that restricts the permissions of newly created files and directories. + pub fn umask(&mut self, umask: u16) -> &mut Self { + self.umask = Some(umask); + self + } + /// Set the timeout for [`UCommand::run`] and similar methods in [`UCommand`]. /// /// After the timeout elapsed these `run` methods (besides [`UCommand::run_no_wait`]) will @@ -1708,6 +1717,19 @@ impl UCommand { } } + #[cfg(unix)] + if let Some(umask) = self.umask { + unsafe { + command.pre_exec(move || { + // We need to allow useless conversions here because in some systems, + // such as freebsd, include u16 constants in libc + #[allow(clippy::useless_conversion)] + libc::umask(umask.into()); + Ok(()) + }); + } + } + (command, captured_stdout, captured_stderr, stdin_pty) } @@ -3872,4 +3894,21 @@ mod tests { .no_stderr() .stdout_is("8\n16\n"); } + + #[cfg(unix)] + #[test] + fn test_altering_umask() { + use uucore::mode::get_umask; + 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 ts = TestScenario::new("util"); + ts.cmd("sh") + .args(&["-c", "umask"]) + .umask(c_umask) + .succeeds() + .stdout_is(expected); + std::assert_eq!(p_umask, get_umask()); // make sure parent umask didn't change + } } From bc3a7bac7202dd398adec0b07a1be21559f204c5 Mon Sep 17 00:00:00 2001 From: sreehari prasad <52113972+matrixhead@users.noreply.github.com> Date: Thu, 16 May 2024 17:02:34 +0530 Subject: [PATCH 2/7] Update tests/common/util.rs Co-authored-by: Terts Diepraam --- tests/common/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/common/util.rs b/tests/common/util.rs index 4a97a4aa004..64419415b93 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -3900,7 +3900,7 @@ mod tests { fn test_altering_umask() { use uucore::mode::get_umask; let p_umask = get_umask(); - //make sure we are not testing against the same 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 ts = TestScenario::new("util"); From a7d4aa4b73ef592ba74d4bbb06eee7fe48277488 Mon Sep 17 00:00:00 2001 From: mhead Date: Fri, 17 May 2024 12:34:19 +0530 Subject: [PATCH 3/7] util: changed to libc type --- tests/common/util.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/common/util.rs b/tests/common/util.rs index 64419415b93..a53c7682c0b 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -8,6 +8,8 @@ #![allow(dead_code)] +#[cfg(unix)] +use libc::mode_t; #[cfg(unix)] use nix::pty::OpenptyResult; use pretty_assertions::assert_eq; @@ -1254,7 +1256,7 @@ pub struct UCommand { terminal_simulation: Option, tmpd: Option>, // drop last #[cfg(unix)] - umask: Option, + umask: Option, } impl UCommand { @@ -1422,7 +1424,7 @@ impl UCommand { #[cfg(unix)] /// The umask is a value that restricts the permissions of newly created files and directories. - pub fn umask(&mut self, umask: u16) -> &mut Self { + pub fn umask(&mut self, umask: mode_t) -> &mut Self { self.umask = Some(umask); self } @@ -1721,10 +1723,7 @@ impl UCommand { if let Some(umask) = self.umask { unsafe { command.pre_exec(move || { - // We need to allow useless conversions here because in some systems, - // such as freebsd, include u16 constants in libc - #[allow(clippy::useless_conversion)] - libc::umask(umask.into()); + libc::umask(umask); Ok(()) }); } From 8891d403f5fac101fbee4801c208b7b8f6fe307b Mon Sep 17 00:00:00 2001 From: mhead Date: Fri, 17 May 2024 12:35:10 +0530 Subject: [PATCH 4/7] chmod: umask, tests port --- tests/by-util/test_chmod.rs | 65 +++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/tests/by-util/test_chmod.rs b/tests/by-util/test_chmod.rs index 1a7c3346bef..cc396a68265 100644 --- a/tests/by-util/test_chmod.rs +++ b/tests/by-util/test_chmod.rs @@ -3,22 +3,18 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. use crate::common::util::{AtPath, TestScenario, UCommand}; -use once_cell::sync::Lazy; use std::fs::{metadata, set_permissions, OpenOptions, Permissions}; use std::os::unix::fs::{OpenOptionsExt, PermissionsExt}; -use std::sync::Mutex; - -use libc::umask; static TEST_FILE: &str = "file"; static REFERENCE_FILE: &str = "reference"; static REFERENCE_PERMS: u32 = 0o247; -static UMASK_MUTEX: Lazy> = Lazy::new(|| Mutex::new(())); struct TestCase { args: Vec<&'static str>, before: u32, after: u32, + umask: Option, } fn make_file(file: &str, mode: u32) { @@ -45,6 +41,9 @@ fn run_single_test(test: &TestCase, at: &AtPath, mut ucmd: UCommand) { for arg in &test.args { ucmd.arg(arg); + if let Some(umask) = test.umask { + ucmd.umask(umask); + } } let r = ucmd.run(); if !r.succeeded() { @@ -73,46 +72,55 @@ fn test_chmod_octal() { args: vec!["0700", TEST_FILE], before: 0o100000, after: 0o100700, + umask: None, }, TestCase { args: vec!["0070", TEST_FILE], before: 0o100000, after: 0o100070, + umask: None, }, TestCase { args: vec!["0007", TEST_FILE], before: 0o100000, after: 0o100007, + umask: None, }, TestCase { args: vec!["-0700", TEST_FILE], before: 0o100700, after: 0o100000, + umask: None, }, TestCase { args: vec!["-0070", TEST_FILE], before: 0o100060, after: 0o100000, + umask: None, }, TestCase { args: vec!["-0007", TEST_FILE], before: 0o100001, after: 0o100000, + umask: None, }, TestCase { args: vec!["+0100", TEST_FILE], before: 0o100600, after: 0o100700, + umask: None, }, TestCase { args: vec!["+0020", TEST_FILE], before: 0o100050, after: 0o100070, + umask: None, }, TestCase { args: vec!["+0004", TEST_FILE], before: 0o100003, after: 0o100007, + umask: None, }, ]; run_tests(tests); @@ -122,86 +130,94 @@ fn test_chmod_octal() { #[allow(clippy::unreadable_literal)] // spell-checker:disable-next-line fn test_chmod_ugoa() { - let _guard = UMASK_MUTEX.lock(); - - let last = unsafe { umask(0) }; let tests = vec![ TestCase { args: vec!["u=rwx", TEST_FILE], before: 0o100000, after: 0o100700, + umask: Some(0), }, TestCase { args: vec!["g=rwx", TEST_FILE], before: 0o100000, after: 0o100070, + umask: Some(0), }, TestCase { args: vec!["o=rwx", TEST_FILE], before: 0o100000, after: 0o100007, + umask: Some(0), }, TestCase { args: vec!["a=rwx", TEST_FILE], before: 0o100000, after: 0o100777, + umask: Some(0), }, TestCase { args: vec!["-r", TEST_FILE], before: 0o100777, after: 0o100333, + umask: Some(0), }, TestCase { args: vec!["-w", TEST_FILE], before: 0o100777, after: 0o100555, + umask: Some(0), }, TestCase { args: vec!["-x", TEST_FILE], before: 0o100777, after: 0o100666, + umask: Some(0), }, ]; run_tests(tests); - unsafe { - umask(0o022); - } let tests = vec![ TestCase { args: vec!["u=rwx", TEST_FILE], before: 0o100000, after: 0o100700, + umask: Some(0o022), }, TestCase { args: vec!["g=rwx", TEST_FILE], before: 0o100000, after: 0o100070, + umask: Some(0o022), }, TestCase { args: vec!["o=rwx", TEST_FILE], before: 0o100000, after: 0o100007, + umask: Some(0o022), }, TestCase { args: vec!["a=rwx", TEST_FILE], before: 0o100000, after: 0o100777, + umask: Some(0o022), }, TestCase { args: vec!["+rw", TEST_FILE], before: 0o100000, after: 0o100644, + umask: Some(0o022), }, TestCase { args: vec!["=rwx", TEST_FILE], before: 0o100000, after: 0o100755, + umask: Some(0o022), }, TestCase { args: vec!["-x", TEST_FILE], before: 0o100777, after: 0o100666, + umask: Some(0o022), }, ]; run_tests(tests); @@ -219,10 +235,6 @@ fn test_chmod_ugoa() { metadata(at.plus("file")).unwrap().permissions().mode(), 0o100577 ); - - unsafe { - umask(last); - } } #[test] @@ -233,26 +245,31 @@ fn test_chmod_ugo_copy() { args: vec!["u=g", TEST_FILE], before: 0o100070, after: 0o100770, + umask: None, }, TestCase { args: vec!["g=o", TEST_FILE], before: 0o100005, after: 0o100055, + umask: None, }, TestCase { args: vec!["o=u", TEST_FILE], before: 0o100200, after: 0o100202, + umask: None, }, TestCase { args: vec!["u-g", TEST_FILE], before: 0o100710, after: 0o100610, + umask: None, }, TestCase { args: vec!["u+g", TEST_FILE], before: 0o100250, after: 0o100750, + umask: None, }, ]; run_tests(tests); @@ -261,18 +278,13 @@ fn test_chmod_ugo_copy() { #[test] #[allow(clippy::unreadable_literal)] fn test_chmod_many_options() { - let _guard = UMASK_MUTEX.lock(); - - let original_umask = unsafe { umask(0) }; let tests = vec![TestCase { args: vec!["-r,a+w", TEST_FILE], before: 0o100444, after: 0o100222, + umask: Some(0), }]; run_tests(tests); - unsafe { - umask(original_umask); - } } #[test] @@ -283,11 +295,13 @@ fn test_chmod_reference_file() { args: vec!["--reference", REFERENCE_FILE, TEST_FILE], before: 0o100070, after: 0o100247, + umask: None, }, TestCase { args: vec!["a-w", "--reference", REFERENCE_FILE, TEST_FILE], before: 0o100070, after: 0o100247, + umask: None, }, ]; let (at, ucmd) = at_and_ucmd!(); @@ -318,9 +332,6 @@ fn test_permission_denied() { #[test] #[allow(clippy::unreadable_literal)] fn test_chmod_recursive() { - let _guard = UMASK_MUTEX.lock(); - - let original_umask = unsafe { umask(0) }; let (at, mut ucmd) = at_and_ucmd!(); at.mkdir("a"); at.mkdir("a/b"); @@ -338,6 +349,7 @@ fn test_chmod_recursive() { .arg("-r,a+w") .arg("a") .arg("z") + .umask(0) .fails() .stderr_is("chmod: Permission denied\n"); @@ -348,10 +360,6 @@ fn test_chmod_recursive() { println!("mode {:o}", at.metadata("a").permissions().mode()); assert_eq!(at.metadata("a").permissions().mode(), 0o40333); assert_eq!(at.metadata("z").permissions().mode(), 0o40333); - - unsafe { - umask(original_umask); - } } #[test] @@ -550,6 +558,7 @@ fn test_mode_after_dash_dash() { args: vec!["--", "-r", TEST_FILE], before: 0o100_777, after: 0o100_333, + umask: None, }, &at, ucmd, From 584a68334627b59fe0082a2a872b22b28421a692 Mon Sep 17 00:00:00 2001 From: mhead Date: Fri, 17 May 2024 13:44:51 +0530 Subject: [PATCH 5/7] mkdir: umask, tests port --- tests/by-util/test_mkdir.rs | 69 +++++++++---------------------------- 1 file changed, 16 insertions(+), 53 deletions(-) diff --git a/tests/by-util/test_mkdir.rs b/tests/by-util/test_mkdir.rs index 8a6eae27bdc..41720745fdc 100644 --- a/tests/by-util/test_mkdir.rs +++ b/tests/by-util/test_mkdir.rs @@ -4,33 +4,22 @@ // file that was distributed with this source code. use crate::common::util::TestScenario; #[cfg(not(windows))] -use libc::{mode_t, umask}; -use once_cell::sync::Lazy; +use libc::mode_t; #[cfg(not(windows))] use std::os::unix::fs::PermissionsExt; -use std::sync::Mutex; - -// tests in `test_mkdir.rs` cannot run in parallel since some tests alter the umask. This may cause -// other tests to run under a wrong set of permissions -// -// when writing a test case, acquire this mutex before proceeding with the main logic of the test -static TEST_MUTEX: Lazy> = Lazy::new(|| Mutex::new(())); #[test] fn test_invalid_arg() { - let _guard = TEST_MUTEX.lock(); new_ucmd!().arg("--definitely-invalid").fails().code_is(1); } #[test] fn test_mkdir_mkdir() { - let _guard = TEST_MUTEX.lock(); new_ucmd!().arg("test_dir").succeeds(); } #[test] fn test_mkdir_verbose() { - let _guard = TEST_MUTEX.lock(); let expected = "mkdir: created directory 'test_dir'\n"; new_ucmd!() .arg("test_dir") @@ -41,8 +30,6 @@ fn test_mkdir_verbose() { #[test] fn test_mkdir_dup_dir() { - let _guard = TEST_MUTEX.lock(); - let scene = TestScenario::new(util_name!()); let test_dir = "test_dir"; @@ -52,13 +39,11 @@ fn test_mkdir_dup_dir() { #[test] fn test_mkdir_mode() { - let _guard = TEST_MUTEX.lock(); new_ucmd!().arg("-m").arg("755").arg("test_dir").succeeds(); } #[test] fn test_mkdir_parent() { - let _guard = TEST_MUTEX.lock(); let scene = TestScenario::new(util_name!()); let test_dir = "parent_dir/child_dir"; @@ -70,14 +55,11 @@ fn test_mkdir_parent() { #[test] fn test_mkdir_no_parent() { - let _guard = TEST_MUTEX.lock(); new_ucmd!().arg("parent_dir/child_dir").fails(); } #[test] fn test_mkdir_dup_dir_parent() { - let _guard = TEST_MUTEX.lock(); - let scene = TestScenario::new(util_name!()); let test_dir = "test_dir"; @@ -88,13 +70,16 @@ fn test_mkdir_dup_dir_parent() { #[cfg(not(windows))] #[test] fn test_mkdir_parent_mode() { - let _guard = TEST_MUTEX.lock(); let (at, mut ucmd) = at_and_ucmd!(); let default_umask: mode_t = 0o160; - let original_umask = unsafe { umask(default_umask) }; - ucmd.arg("-p").arg("a/b").succeeds().no_stderr().no_stdout(); + ucmd.arg("-p") + .arg("a/b") + .umask(default_umask) + .succeeds() + .no_stderr() + .no_stdout(); assert!(at.dir_exists("a")); // parents created by -p have permissions set to "=rwx,u+wx" @@ -108,25 +93,21 @@ fn test_mkdir_parent_mode() { at.metadata("a/b").permissions().mode() as mode_t, (!default_umask & 0o777) + 0o40000 ); - - unsafe { - umask(original_umask); - } } #[cfg(not(windows))] #[test] fn test_mkdir_parent_mode_check_existing_parent() { - let _guard = TEST_MUTEX.lock(); let (at, mut ucmd) = at_and_ucmd!(); at.mkdir("a"); + let parent_a_perms = at.metadata("a").permissions().mode(); let default_umask: mode_t = 0o160; - let original_umask = unsafe { umask(default_umask) }; ucmd.arg("-p") .arg("a/b/c") + .umask(default_umask) .succeeds() .no_stderr() .no_stdout(); @@ -135,7 +116,7 @@ fn test_mkdir_parent_mode_check_existing_parent() { // parent dirs that already exist do not get their permissions modified assert_eq!( at.metadata("a").permissions().mode() as mode_t, - (!original_umask & 0o777) + 0o40000 + parent_a_perms ); assert!(at.dir_exists("a/b")); assert_eq!( @@ -147,16 +128,10 @@ fn test_mkdir_parent_mode_check_existing_parent() { at.metadata("a/b/c").permissions().mode() as mode_t, (!default_umask & 0o777) + 0o40000 ); - - unsafe { - umask(original_umask); - } } #[test] fn test_mkdir_dup_file() { - let _guard = TEST_MUTEX.lock(); - let scene = TestScenario::new(util_name!()); let test_file = "test_file.txt"; @@ -171,7 +146,6 @@ fn test_mkdir_dup_file() { #[test] #[cfg(not(windows))] fn test_symbolic_mode() { - let _guard = TEST_MUTEX.lock(); let (at, mut ucmd) = at_and_ucmd!(); let test_dir = "test_dir"; @@ -183,24 +157,23 @@ fn test_symbolic_mode() { #[test] #[cfg(not(windows))] fn test_symbolic_alteration() { - let _guard = TEST_MUTEX.lock(); let (at, mut ucmd) = at_and_ucmd!(); let test_dir = "test_dir"; let default_umask = 0o022; - let original_umask = unsafe { umask(default_umask) }; - ucmd.arg("-m").arg("-w").arg(test_dir).succeeds(); + ucmd.arg("-m") + .arg("-w") + .arg(test_dir) + .umask(default_umask) + .succeeds(); let perms = at.metadata(test_dir).permissions().mode(); assert_eq!(perms, 0o40577); - - unsafe { umask(original_umask) }; } #[test] #[cfg(not(windows))] fn test_multi_symbolic() { - let _guard = TEST_MUTEX.lock(); let (at, mut ucmd) = at_and_ucmd!(); let test_dir = "test_dir"; @@ -211,7 +184,6 @@ fn test_multi_symbolic() { #[test] fn test_recursive_reporting() { - let _guard = TEST_MUTEX.lock(); let test_dir = "test_dir/test_dir_a/test_dir_b"; new_ucmd!() @@ -238,8 +210,6 @@ fn test_recursive_reporting() { #[test] fn test_mkdir_trailing_dot() { - let _guard = TEST_MUTEX.lock(); - new_ucmd!().arg("-p").arg("-v").arg("test_dir").succeeds(); new_ucmd!() @@ -265,20 +235,13 @@ fn test_mkdir_trailing_dot() { #[cfg(not(windows))] fn test_umask_compliance() { fn test_single_case(umask_set: mode_t) { - let _guard = TEST_MUTEX.lock(); - let test_dir = "test_dir"; let (at, mut ucmd) = at_and_ucmd!(); - let original_umask = unsafe { umask(umask_set) }; - - ucmd.arg(test_dir).succeeds(); + ucmd.arg(test_dir).umask(umask_set).succeeds(); let perms = at.metadata(test_dir).permissions().mode() as mode_t; assert_eq!(perms, (!umask_set & 0o0777) + 0o40000); // before compare, add the set GUID, UID bits - unsafe { - umask(original_umask); - } // set umask back to original } for i in 0o0..0o027 { From a83a8ad3a714641cbd54c2150be5279b5e541005 Mon Sep 17 00:00:00 2001 From: mhead Date: Fri, 17 May 2024 13:52:30 +0530 Subject: [PATCH 6/7] cp: umask, test --- tests/by-util/test_cp.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 5164070c46c..ae1c402e4e0 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -1718,18 +1718,17 @@ fn test_cp_preserve_links_case_7() { #[test] #[cfg(unix)] fn test_cp_no_preserve_mode() { - use libc::umask; use uucore::fs as uufs; let (at, mut ucmd) = at_and_ucmd!(); at.touch("a"); at.set_mode("a", 0o731); - unsafe { umask(0o077) }; ucmd.arg("-a") .arg("--no-preserve=mode") .arg("a") .arg("b") + .umask(0o077) .succeeds(); assert!(at.file_exists("b")); @@ -1737,8 +1736,6 @@ fn test_cp_no_preserve_mode() { let metadata_b = std::fs::metadata(at.subdir.join("b")).unwrap(); let permission_b = uufs::display_permissions(&metadata_b, false); assert_eq!(permission_b, "rw-------".to_string()); - - unsafe { umask(0o022) }; } #[test] @@ -2535,8 +2532,6 @@ fn test_copy_symlink_force() { fn test_no_preserve_mode() { use std::os::unix::prelude::MetadataExt; - use uucore::mode::get_umask; - const PERMS_ALL: u32 = if cfg!(target_os = "freebsd") { // Only the superuser can set the sticky bit on a file. 0o6777 @@ -2547,12 +2542,13 @@ 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; ucmd.arg("file") .arg("dest") + .umask(umask) .succeeds() .no_stderr() .no_stdout(); - let umask = get_umask(); // remove sticky bit, setuid and setgid bit; apply umask let expected_perms = PERMS_ALL & !0o7000 & !umask; assert_eq!( From 9b5be241621567fc5437401b64cb5be127d50409 Mon Sep 17 00:00:00 2001 From: mhead Date: Sat, 18 May 2024 21:25:10 +0530 Subject: [PATCH 7/7] various fixes --- tests/by-util/test_chmod.rs | 9 +++++++-- tests/by-util/test_cp.rs | 6 +++--- tests/by-util/test_mkdir.rs | 5 +---- tests/common/util.rs | 13 ++++++++++++- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/tests/by-util/test_chmod.rs b/tests/by-util/test_chmod.rs index cc396a68265..32bb7a96641 100644 --- a/tests/by-util/test_chmod.rs +++ b/tests/by-util/test_chmod.rs @@ -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); @@ -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] diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index ae1c402e4e0..f5a81c2165b 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -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 diff --git a/tests/by-util/test_mkdir.rs b/tests/by-util/test_mkdir.rs index 41720745fdc..04d3922206e 100644 --- a/tests/by-util/test_mkdir.rs +++ b/tests/by-util/test_mkdir.rs @@ -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, diff --git a/tests/common/util.rs b/tests/common/util.rs index a53c7682c0b..047d2c57950 100644 --- a/tests/common/util.rs +++ b/tests/common/util.rs @@ -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" + } else { + "0002\n" + }; + let ts = TestScenario::new("util"); ts.cmd("sh") .args(&["-c", "umask"])