diff --git a/src/uu/chmod/Cargo.toml b/src/uu/chmod/Cargo.toml index cd236e95e3a..47294367626 100644 --- a/src/uu/chmod/Cargo.toml +++ b/src/uu/chmod/Cargo.toml @@ -21,9 +21,6 @@ fluent = { workspace = true } thiserror = { workspace = true } uucore = { workspace = true, features = ["fs", "mode", "perms"] } -[target.'cfg(all(unix, not(any(target_os = "aix", target_os = "hurd", target_os = "redox"))))'.dependencies] -uucore = { workspace = true, features = ["safe-traversal"] } - [features] diagnostics = ["uucore/diagnostics"] diff --git a/src/uu/chmod/src/chmod.rs b/src/uu/chmod/src/chmod.rs index eb182a7eab3..f586ef8a681 100644 --- a/src/uu/chmod/src/chmod.rs +++ b/src/uu/chmod/src/chmod.rs @@ -21,7 +21,7 @@ use uucore::fs::{FileInformation, display_permissions_unix, path_is_root_dir}; use uucore::mode; use uucore::perms::{TraverseSymlinks, configure_symlink_and_recursion}; -#[cfg(not(any(target_os = "aix", target_os = "hurd", target_os = "redox")))] +#[cfg(not(target_os = "redox"))] use uucore::safe_traversal::{DirFd, SymlinkBehavior}; use uucore::{format_usage, show, show_error}; @@ -416,37 +416,6 @@ impl Chmoder { } } - /// Handle symlinks during directory traversal based on traversal mode - #[cfg(target_os = "aix")] - fn handle_symlink_during_traversal( - &self, - path: &Path, - is_command_line_arg: bool, - ancestors: &mut HashSet, - ) -> UResult<()> { - let should_follow_symlink = match self.traverse_symlinks { - TraverseSymlinks::All => true, - TraverseSymlinks::First => is_command_line_arg, - TraverseSymlinks::None => false, - }; - - if !should_follow_symlink { - return self.chmod_file_internal(path, false); - } - - match fs::metadata(path) { - Ok(meta) if meta.is_dir() => self.walk_dir_with_context(path, false, ancestors), - Ok(_) => { - // It's a file symlink, chmod it - self.chmod_file(path) - } - Err(_) => { - // Dangling symlink, chmod it without dereferencing - self.chmod_file_internal(path, false) - } - } - } - fn print_neither_changed(file: OsString) -> std::io::Result<()> { use std::io::{Write as _, stdout}; writeln!( @@ -552,7 +521,7 @@ impl Chmoder { } // Non-safe traversal implementation for platforms without safe_traversal support - #[cfg(any(target_os = "aix", target_os = "hurd", target_os = "redox"))] + #[cfg(target_os = "redox")] fn walk_dir_with_context( &self, file_path: &Path, @@ -598,24 +567,9 @@ impl Chmoder { } } for path in paths_in_this_dir { - #[cfg(target_os = "aix")] - { - if path.is_symlink() { - r = self - .handle_symlink_during_recursion(&path, ancestors) - .and(r); - } else { - r = self - .walk_dir_with_context(path.as_path(), false, ancestors) - .and(r); - } - } - #[cfg(any(target_os = "hurd", target_os = "redox"))] - { - r = self - .walk_dir_with_context(path.as_path(), false, ancestors) - .and(r); - } + r = self + .walk_dir_with_context(path.as_path(), false, ancestors) + .and(r); } // Backtrack: remove this directory from ancestors so sibling subtrees @@ -627,7 +581,7 @@ impl Chmoder { r } - #[cfg(not(any(target_os = "aix", target_os = "hurd", target_os = "redox")))] + #[cfg(not(target_os = "redox"))] fn walk_dir_with_context( &self, file_path: &Path, @@ -672,7 +626,7 @@ impl Chmoder { r } - #[cfg(not(any(target_os = "aix", target_os = "hurd", target_os = "redox")))] + #[cfg(not(target_os = "redox"))] fn safe_traverse_dir( &self, dir_fd: &DirFd, @@ -770,7 +724,7 @@ impl Chmoder { r } - #[cfg(not(any(target_os = "aix", target_os = "hurd", target_os = "redox")))] + #[cfg(not(target_os = "redox"))] fn handle_symlink_during_safe_recursion( &self, path: &Path, @@ -813,7 +767,7 @@ impl Chmoder { } } - #[cfg(not(any(target_os = "aix", target_os = "hurd", target_os = "redox")))] + #[cfg(not(target_os = "redox"))] fn safe_chmod_file( &self, file_path: &Path, @@ -842,16 +796,6 @@ impl Chmoder { Ok(()) } - #[cfg(target_os = "aix")] - fn handle_symlink_during_recursion( - &self, - path: &Path, - ancestors: &mut HashSet, - ) -> UResult<()> { - // Use the common symlink handling logic - self.handle_symlink_during_traversal(path, false, ancestors) - } - fn chmod_file(&self, file: &Path) -> UResult<()> { self.chmod_file_internal(file, self.dereference) } diff --git a/src/uu/chown/Cargo.toml b/src/uu/chown/Cargo.toml index ed5c57c7ccc..4704f623e04 100644 --- a/src/uu/chown/Cargo.toml +++ b/src/uu/chown/Cargo.toml @@ -20,9 +20,6 @@ clap = { workspace = true } fluent = { workspace = true } uucore = { workspace = true, features = ["entries", "fs", "perms"] } -[target.'cfg(all(unix, not(any(target_os = "aix", target_os = "hurd", target_os = "redox"))))'.dependencies] -uucore = { workspace = true, features = ["safe-traversal"] } - [lints] workspace = true diff --git a/src/uu/du/Cargo.toml b/src/uu/du/Cargo.toml index dd648853092..f674b5ed0b0 100644 --- a/src/uu/du/Cargo.toml +++ b/src/uu/du/Cargo.toml @@ -31,7 +31,7 @@ uucore = { workspace = true, features = [ "time", ] } -[target.'cfg(all(unix, not(any(target_os = "aix", target_os = "hurd", target_os = "redox"))))'.dependencies] +[target.'cfg(all(unix, not(target_os = "redox")))'.dependencies] uucore = { workspace = true, features = ["safe-traversal"] } [target.'cfg(windows)'.dependencies] diff --git a/src/uu/install/Cargo.toml b/src/uu/install/Cargo.toml index bf7678ce15c..bee20905846 100644 --- a/src/uu/install/Cargo.toml +++ b/src/uu/install/Cargo.toml @@ -28,9 +28,6 @@ uucore = { workspace = true, default-features = true, features = [ "process", ] } -[target.'cfg(all(unix, not(any(target_os = "aix", target_os = "hurd", target_os = "redox"))))'.dependencies] -uucore = { workspace = true, features = ["safe-traversal"] } - [target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] rustix = { workspace = true, features = ["fs"] } selinux = { workspace = true, optional = true } diff --git a/src/uu/rm/Cargo.toml b/src/uu/rm/Cargo.toml index 9ac240d9b11..23c840551d1 100644 --- a/src/uu/rm/Cargo.toml +++ b/src/uu/rm/Cargo.toml @@ -22,7 +22,7 @@ indicatif = { workspace = true } thiserror = { workspace = true } uucore = { workspace = true, features = ["fs", "parser", "quoting-style"] } -[target.'cfg(all(unix, not(any(target_os = "aix", target_os = "hurd", target_os = "redox"))))'.dependencies] +[target.'cfg(all(unix, not(target_os = "redox")))'.dependencies] uucore = { workspace = true, features = ["safe-traversal"] } [target.'cfg(unix)'.dependencies] diff --git a/src/uucore/src/lib/features.rs b/src/uucore/src/lib/features.rs index 062af7b3f3c..83dff9de82d 100644 --- a/src/uucore/src/lib/features.rs +++ b/src/uucore/src/lib/features.rs @@ -86,11 +86,7 @@ pub mod proc_info; pub mod process; #[cfg(all(unix, feature = "safe-copy"))] pub mod safe_copy; -#[cfg(all( - feature = "safe-traversal", - unix, - not(any(target_os = "aix", target_os = "hurd", target_os = "redox")) -))] +#[cfg(all(feature = "safe-traversal", unix, not(target_os = "redox")))] pub mod safe_traversal; #[cfg(all(target_os = "linux", feature = "tty"))] pub mod tty; diff --git a/src/uucore/src/lib/features/safe_traversal.rs b/src/uucore/src/lib/features/safe_traversal.rs index 5925b6236e6..b8bd8183fb4 100644 --- a/src/uucore/src/lib/features/safe_traversal.rs +++ b/src/uucore/src/lib/features/safe_traversal.rs @@ -6,7 +6,7 @@ // spell-checker:ignore CLOEXEC RDONLY TOCTOU closedir dirp fdopendir fstatat openat REMOVEDIR unlinkat smallfile // spell-checker:ignore RAII dirfd fchownat fchown FchmodatFlags fchmodat fchmod mkdirat CREAT WRONLY ELOOP ENOTDIR EXCL EEXIST // spell-checker:ignore atimensec mtimensec ctimensec opath chmods fakeroot fakechroot EOVERFLOW chowned chmoded -// spell-checker:ignore LARGEFILE getdents +// spell-checker:ignore LARGEFILE getdents atim mtim ctim statat // Safe directory traversal using openat() and related syscalls // This module provides TOCTOU-safe filesystem operations for recursive traversal @@ -941,8 +941,16 @@ impl MetadataExt for Metadata { } fn atime(&self) -> i64 { - #[allow(clippy::useless_conversion)] - self.stat.st_atime.into() + // aix and hurd only have the timespec fields + #[cfg(any(target_os = "aix", target_os = "hurd"))] + { + self.stat.st_atim.tv_sec as _ + } + #[cfg(not(any(target_os = "aix", target_os = "hurd")))] + { + #[allow(clippy::useless_conversion)] + self.stat.st_atime.into() + } } fn atime_nsec(&self) -> i64 { @@ -952,7 +960,12 @@ impl MetadataExt for Metadata { (self.stat.st_atimensec as i64) } - #[cfg(not(target_os = "netbsd"))] + #[cfg(any(target_os = "aix", target_os = "hurd"))] + { + self.stat.st_atim.tv_nsec as _ + } + + #[cfg(not(any(target_os = "netbsd", target_os = "aix", target_os = "hurd")))] { #[allow(clippy::unnecessary_cast)] (self.stat.st_atime_nsec as i64) @@ -960,8 +973,15 @@ impl MetadataExt for Metadata { } fn mtime(&self) -> i64 { - #[allow(clippy::useless_conversion)] - self.stat.st_mtime.into() + #[cfg(any(target_os = "aix", target_os = "hurd"))] + { + self.stat.st_mtim.tv_sec as _ + } + #[cfg(not(any(target_os = "aix", target_os = "hurd")))] + { + #[allow(clippy::useless_conversion)] + self.stat.st_mtime.into() + } } fn mtime_nsec(&self) -> i64 { @@ -970,7 +990,11 @@ impl MetadataExt for Metadata { #[allow(clippy::unnecessary_cast)] (self.stat.st_mtimensec as i64) } - #[cfg(not(target_os = "netbsd"))] + #[cfg(any(target_os = "aix", target_os = "hurd"))] + { + self.stat.st_mtim.tv_nsec as _ + } + #[cfg(not(any(target_os = "netbsd", target_os = "aix", target_os = "hurd")))] { #[allow(clippy::unnecessary_cast)] (self.stat.st_mtime_nsec as i64) @@ -978,8 +1002,15 @@ impl MetadataExt for Metadata { } fn ctime(&self) -> i64 { - #[allow(clippy::useless_conversion)] - self.stat.st_ctime.into() + #[cfg(any(target_os = "aix", target_os = "hurd"))] + { + self.stat.st_ctim.tv_sec as _ + } + #[cfg(not(any(target_os = "aix", target_os = "hurd")))] + { + #[allow(clippy::useless_conversion)] + self.stat.st_ctime.into() + } } fn ctime_nsec(&self) -> i64 { @@ -988,7 +1019,11 @@ impl MetadataExt for Metadata { #[allow(clippy::unnecessary_cast)] (self.stat.st_ctimensec as i64) } - #[cfg(not(target_os = "netbsd"))] + #[cfg(any(target_os = "aix", target_os = "hurd"))] + { + self.stat.st_ctim.tv_nsec as _ + } + #[cfg(not(any(target_os = "netbsd", target_os = "aix", target_os = "hurd")))] { #[allow(clippy::unnecessary_cast)] (self.stat.st_ctime_nsec as i64) diff --git a/src/uucore/src/lib/lib.rs b/src/uucore/src/lib/lib.rs index 928f47668e8..903450bb77b 100644 --- a/src/uucore/src/lib/lib.rs +++ b/src/uucore/src/lib/lib.rs @@ -105,11 +105,7 @@ pub use crate::features::pipes; pub use crate::features::process; #[cfg(all(unix, feature = "safe-copy"))] pub use crate::features::safe_copy; -#[cfg(all( - feature = "safe-traversal", - unix, - not(any(target_os = "aix", target_os = "hurd", target_os = "redox")) -))] +#[cfg(all(feature = "safe-traversal", unix, not(target_os = "redox")))] pub use crate::features::safe_traversal; #[cfg(all( feature = "signals",