Skip to content

Commit 1f6acdb

Browse files
committed
refactor(cp): simplify mode consts
1 parent 3539e32 commit 1f6acdb

2 files changed

Lines changed: 9 additions & 31 deletions

File tree

src/uu/cp/src/cp.rs

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
833833
// We follow it here by setting it to permit all user modes, and passing the original down
834834
// functions such that it is used when creating new dir/file and not preserving mode.
835835
#[cfg(unix)]
836-
let orig_umask = unsafe { libc::umask(!0o700) as u32 };
836+
let orig_umask = unsafe { libc::umask(!libc::S_IRWXU) as u32 };
837837

838838
if let Err(error) = copy(
839839
&sources,
@@ -2744,33 +2744,11 @@ fn handle_created_mode(mode: Preserve, is_dir: bool, source_mode: u32, umask: u3
27442744
const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32;
27452745

27462746
if let Preserve::No { explicit } = mode {
2747-
#[cfg(not(any(
2748-
target_os = "android",
2749-
target_os = "macos",
2750-
target_os = "freebsd",
2751-
target_os = "redox",
2752-
)))]
2753-
{
2754-
(if explicit {
2755-
if is_dir { S_IRWXUGO } else { MODE_RW_UGO }
2756-
} else {
2757-
source_mode & S_IRWXUGO
2758-
}) & !umask
2759-
}
2760-
2761-
#[cfg(any(
2762-
target_os = "android",
2763-
target_os = "macos",
2764-
target_os = "freebsd",
2765-
target_os = "redox",
2766-
))]
2767-
{
2768-
(if explicit {
2769-
if is_dir { S_IRWXUGO } else { MODE_RW_UGO }
2770-
} else {
2771-
source_mode & S_IRWXUGO
2772-
}) & !umask
2773-
}
2747+
(if explicit {
2748+
if is_dir { S_IRWXUGO } else { MODE_RW_UGO }
2749+
} else {
2750+
source_mode & S_IRWXUGO
2751+
}) & !umask
27742752
} else {
27752753
source_mode & S_IRWXUGO
27762754
}

tests/by-util/test_cp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7920,7 +7920,7 @@ fn test_cp_existing_no_preserve_dir() {
79207920
scene.cmd("mkdir").arg("d1").succeeds();
79217921
scene.cmd("mkdir").arg("d2").succeeds();
79227922
scene.cmd("chmod").arg("770").arg("d1").succeeds();
7923-
scene.cmd("chmod").arg("700").arg("d2").succeeds();
7923+
scene.cmd("chmod").arg("707").arg("d2").succeeds();
79247924
let d2_mode = at.metadata("d2").mode();
79257925

79267926
scene
@@ -7978,7 +7978,7 @@ fn test_cp_existing_default_dir() {
79787978
scene.cmd("mkdir").arg("d1").succeeds();
79797979
scene.cmd("mkdir").arg("d2").succeeds();
79807980
scene.cmd("chmod").arg("770").arg("d1").succeeds();
7981-
scene.cmd("chmod").arg("700").arg("d2").succeeds();
7981+
scene.cmd("chmod").arg("707").arg("d2").succeeds();
79827982
let d2_mode = at.metadata("d2").mode();
79837983

79847984
scene
@@ -8036,7 +8036,7 @@ fn test_cp_existing_preserve_dir() {
80368036
scene.cmd("mkdir").arg("d1").succeeds();
80378037
scene.cmd("mkdir").arg("d2").succeeds();
80388038
scene.cmd("chmod").arg("770").arg("d1").succeeds();
8039-
scene.cmd("chmod").arg("700").arg("d2").succeeds();
8039+
scene.cmd("chmod").arg("707").arg("d2").succeeds();
80408040
let d1_mode = at.metadata("d1").mode();
80418041

80428042
scene

0 commit comments

Comments
 (0)