Skip to content

Commit d971b4f

Browse files
committed
safe-traversal is always used on linux, adjust the cfg
1 parent 64348d8 commit d971b4f

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

src/uucore/src/lib/features.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub mod pipes;
6767
pub mod proc_info;
6868
#[cfg(all(unix, feature = "process"))]
6969
pub mod process;
70-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
70+
#[cfg(target_os = "linux")]
7171
pub mod safe_traversal;
7272
#[cfg(all(target_os = "linux", feature = "tty"))]
7373
pub mod tty;

src/uucore/src/lib/features/perms.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ use libc::{gid_t, uid_t};
1818
use options::traverse;
1919
use std::ffi::OsString;
2020

21-
#[cfg(not(all(target_os = "linux", feature = "safe-traversal")))]
21+
#[cfg(not(target_os = "linux"))]
2222
use walkdir::WalkDir;
2323

24-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
24+
#[cfg(target_os = "linux")]
2525
use crate::features::safe_traversal::DirFd;
2626

2727
use std::ffi::CString;
@@ -308,7 +308,7 @@ impl ChownExecutor {
308308

309309
let ret = if self.matched(meta.uid(), meta.gid()) {
310310
// Use safe syscalls for root directory to prevent TOCTOU attacks
311-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
311+
#[cfg(target_os = "linux")]
312312
let chown_result = if path.is_dir() {
313313
// For directories, use safe traversal from the start
314314
match DirFd::open(path) {
@@ -331,7 +331,7 @@ impl ChownExecutor {
331331
)
332332
};
333333

334-
#[cfg(not(all(target_os = "linux", feature = "safe-traversal")))]
334+
#[cfg(not(target_os = "linux"))]
335335
let chown_result = wrap_chown(
336336
path,
337337
&meta,
@@ -365,11 +365,11 @@ impl ChownExecutor {
365365
};
366366

367367
if self.recursive {
368-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
368+
#[cfg(target_os = "linux")]
369369
{
370370
ret | self.safe_dive_into(&root)
371371
}
372-
#[cfg(not(all(target_os = "linux", feature = "safe-traversal")))]
372+
#[cfg(not(target_os = "linux"))]
373373
{
374374
ret | self.dive_into(&root)
375375
}
@@ -378,7 +378,7 @@ impl ChownExecutor {
378378
}
379379
}
380380

381-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
381+
#[cfg(target_os = "linux")]
382382
fn safe_chown_dir(
383383
&self,
384384
dir_fd: &DirFd,
@@ -432,7 +432,7 @@ impl ChownExecutor {
432432
Ok(String::new())
433433
}
434434

435-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
435+
#[cfg(target_os = "linux")]
436436
fn safe_dive_into<P: AsRef<Path>>(&self, root: P) -> i32 {
437437
let root = root.as_ref();
438438

@@ -458,7 +458,7 @@ impl ChownExecutor {
458458
ret
459459
}
460460

461-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
461+
#[cfg(target_os = "linux")]
462462
fn safe_traverse_dir(&self, dir_fd: &DirFd, dir_path: &Path, ret: &mut i32) {
463463
// Read directory entries
464464
let entries = match dir_fd.read_dir() {
@@ -563,7 +563,7 @@ impl ChownExecutor {
563563
}
564564
}
565565

566-
#[cfg(not(all(target_os = "linux", feature = "safe-traversal")))]
566+
#[cfg(not(target_os = "linux"))]
567567
#[allow(clippy::cognitive_complexity)]
568568
fn dive_into<P: AsRef<Path>>(&self, root: P) -> i32 {
569569
let root = root.as_ref();
@@ -700,7 +700,7 @@ impl ChownExecutor {
700700
}
701701

702702
/// Try to open directory with error reporting
703-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
703+
#[cfg(target_os = "linux")]
704704
fn try_open_dir(&self, path: &Path) -> Option<DirFd> {
705705
DirFd::open(path)
706706
.map_err(|e| {
@@ -713,7 +713,7 @@ impl ChownExecutor {
713713

714714
/// Report ownership change with proper verbose output
715715
/// Returns 0 on success
716-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
716+
#[cfg(target_os = "linux")]
717717
fn report_ownership_change_success(
718718
&self,
719719
path: &Path,

src/uucore/src/lib/features/safe_traversal.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
// spell-checker:ignore CLOEXEC RDONLY TOCTOU closedir dirp fdopendir fstatat openat REMOVEDIR unlinkat smallfile
1212
// spell-checker:ignore RAII dirfd fchownat fchown FchmodatFlags fchmodat fchmod
1313

14-
#![cfg(target_os = "linux")]
15-
1614
#[cfg(test)]
1715
use std::os::unix::ffi::OsStringExt;
1816

src/uucore/src/lib/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub use crate::features::perms;
9292
pub use crate::features::pipes;
9393
#[cfg(all(unix, feature = "process"))]
9494
pub use crate::features::process;
95-
#[cfg(all(target_os = "linux", feature = "safe-traversal"))]
95+
#[cfg(target_os = "linux")]
9696
pub use crate::features::safe_traversal;
9797
#[cfg(all(unix, not(target_os = "fuchsia"), feature = "signals"))]
9898
pub use crate::features::signals;

0 commit comments

Comments
 (0)