From 529467d8e5d2401a78c36638f3c6109e06b12e7e Mon Sep 17 00:00:00 2001 From: oech3 <79379754+oech3@users.noreply.github.com> Date: Wed, 6 May 2026 16:57:56 +0900 Subject: [PATCH] reduce usage of nix::unistd::geteuid --- tests/by-util/test_chown.rs | 4 +--- tests/by-util/test_date.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/by-util/test_chown.rs b/tests/by-util/test_chown.rs index f7c08b4a0..dc2769fb2 100644 --- a/tests/by-util/test_chown.rs +++ b/tests/by-util/test_chown.rs @@ -4,8 +4,6 @@ // file that was distributed with this source code. // spell-checker:ignore (words) agroupthatdoesntexist auserthatdoesntexist cuuser groupname notexisting passgrp -#[cfg(any(target_os = "linux", target_os = "android"))] -use uucore::process::geteuid; use uutests::util::{CmdResult, TestScenario, is_ci, run_ucmd_as_root}; use uutests::util_name; use uutests::{at_and_ucmd, new_ucmd}; @@ -750,7 +748,7 @@ fn test_root_preserve() { #[cfg(any(target_os = "linux", target_os = "android"))] #[test] fn test_big_p() { - if geteuid() != 0 { + if !rustix::process::geteuid().is_root() { new_ucmd!() .arg("-RP") .arg("bin") diff --git a/tests/by-util/test_date.rs b/tests/by-util/test_date.rs index a2976bf9b..af1c2ae2a 100644 --- a/tests/by-util/test_date.rs +++ b/tests/by-util/test_date.rs @@ -12,7 +12,7 @@ use jiff::tz::TimeZone; use jiff::{Timestamp, ToSpan}; use regex::Regex; #[cfg(all(unix, not(target_os = "macos")))] -use uucore::process::geteuid; +use rustix::process::geteuid; use uutests::util::TestScenario; #[cfg(unix)] use uutests::util::is_locale_available; @@ -425,7 +425,7 @@ fn test_date_format_literal() { #[test] #[cfg(all(unix, not(target_os = "macos")))] fn test_date_set_valid() { - if geteuid() == 0 { + if geteuid().is_root() { new_ucmd!() .arg("--set") .arg("2020-03-12 13:30:00+08:00") @@ -446,7 +446,7 @@ fn test_date_set_invalid() { #[test] #[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))] fn test_date_set_permissions_error() { - if !(geteuid() == 0 || uucore::os::is_wsl_1()) { + if !(geteuid().is_root() || uucore::os::is_wsl_1()) { let result = new_ucmd!() .arg("--set") .arg("2020-03-11 21:45:00+08:00") @@ -460,7 +460,7 @@ fn test_date_set_permissions_error() { #[cfg(all(unix, not(any(target_os = "android", target_os = "macos"))))] fn test_date_set_hyphen_prefixed_values() { // test -s flag accepts hyphen-prefixed values like "-3 days" - if !(geteuid() == 0 || uucore::os::is_wsl_1()) { + if !(geteuid().is_root() || uucore::os::is_wsl_1()) { let test_cases = vec!["-1 hour", "-2 days", "-3 weeks", "-1 month"]; for date_str in test_cases { @@ -494,7 +494,7 @@ fn test_date_set_mac_unavailable() { #[test] #[cfg(all(unix, not(target_os = "macos")))] fn test_date_set_valid_2() { - if geteuid() == 0 { + if geteuid().is_root() { new_ucmd!() .arg("--set") .arg("Sat 20 Mar 2021 14:53:01 AWST") // spell-checker:disable-line @@ -575,7 +575,7 @@ fn test_date_for_file_mtime() { #[test] #[cfg(all(unix, not(target_os = "macos")))] fn test_date_set_valid_3() { - if geteuid() == 0 { + if geteuid().is_root() { new_ucmd!() .arg("--set") .arg("Sat 20 Mar 2021 14:53:01") // Local timezone @@ -588,7 +588,7 @@ fn test_date_set_valid_3() { #[test] #[cfg(all(unix, not(target_os = "macos")))] fn test_date_set_valid_4() { - if geteuid() == 0 { + if geteuid().is_root() { new_ucmd!() .arg("--set") .arg("2020-03-11 21:45:00") // Local timezone