Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/uu/chmod/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
74 changes: 9 additions & 65 deletions src/uu/chmod/src/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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<FileInformation>,
) -> 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!(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -842,16 +796,6 @@ impl Chmoder {
Ok(())
}

#[cfg(target_os = "aix")]
fn handle_symlink_during_recursion(
&self,
path: &Path,
ancestors: &mut HashSet<FileInformation>,
) -> 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)
}
Expand Down
3 changes: 0 additions & 3 deletions src/uu/chown/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/uu/du/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 0 additions & 3 deletions src/uu/install/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion src/uu/rm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 1 addition & 5 deletions src/uucore/src/lib/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
55 changes: 45 additions & 10 deletions src/uucore/src/lib/features/safe_traversal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -952,16 +960,28 @@ 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)
}
}

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 {
Expand All @@ -970,16 +990,27 @@ 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)
}
}

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 {
Expand All @@ -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)
Expand Down
6 changes: 1 addition & 5 deletions src/uucore/src/lib/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading