From 4460748f64652712dfc89dc2ebeaefee9917be28 Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Sun, 25 Oct 2026 15:06:06 +0900 Subject: [PATCH] test_sync.rs: don't depend on chmod --- tests/by-util/test_sync.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/by-util/test_sync.rs b/tests/by-util/test_sync.rs index 8516aac9d77..f74e9374730 100644 --- a/tests/by-util/test_sync.rs +++ b/tests/by-util/test_sync.rs @@ -63,9 +63,9 @@ fn test_sync_data_but_not_file() { } #[cfg(any(target_os = "linux", target_os = "android"))] -#[cfg(feature = "chmod")] #[test] fn test_sync_no_permission_dir() { + use std::os::unix::fs::PermissionsExt as _; use uutests::util::TestScenario; use uutests::util_name; @@ -73,8 +73,11 @@ fn test_sync_no_permission_dir() { let at = &ts.fixtures; let dir = "foo"; at.mkdir_all(dir); + let path = at.subdir.as_path().join(dir); + let mut perms = fs::metadata(&path).unwrap().permissions(); + perms.set_mode(0o0); + fs::set_permissions(&path, perms).unwrap(); - ts.ccmd("chmod").arg("0").arg(dir).succeeds(); let result = ts.ucmd().arg("--data").arg(dir).fails(); result.stderr_contains("sync: error opening 'foo': Permission denied"); let result = ts.ucmd().arg(dir).fails(); @@ -82,9 +85,9 @@ fn test_sync_no_permission_dir() { } #[cfg(not(windows))] -#[cfg(feature = "chmod")] #[test] fn test_sync_no_permission_file() { + use std::os::unix::fs::PermissionsExt as _; use uutests::util::TestScenario; use uutests::util_name; @@ -92,8 +95,11 @@ fn test_sync_no_permission_file() { let at = &ts.fixtures; let f = "file"; at.touch(f); + let path = at.subdir.as_path().join(f); + let mut perms = fs::metadata(&path).unwrap().permissions(); + perms.set_mode(0o200); + fs::set_permissions(&path, perms).unwrap(); - ts.ccmd("chmod").arg("0200").arg(f).succeeds(); ts.ucmd().arg(f).succeeds(); }