Skip to content

Commit 18bfa3e

Browse files
committed
refactor(cp): simplify mode consts
1 parent a72cbf7 commit 18bfa3e

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,
@@ -2734,33 +2734,11 @@ fn handle_created_mode(mode: Preserve, is_dir: bool, source_mode: u32, umask: u3
27342734
const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32;
27352735

27362736
if let Preserve::No { explicit } = mode {
2737-
#[cfg(not(any(
2738-
target_os = "android",
2739-
target_os = "macos",
2740-
target_os = "freebsd",
2741-
target_os = "redox",
2742-
)))]
2743-
{
2744-
(if explicit {
2745-
if is_dir { S_IRWXUGO } else { MODE_RW_UGO }
2746-
} else {
2747-
source_mode & S_IRWXUGO
2748-
}) & !umask
2749-
}
2750-
2751-
#[cfg(any(
2752-
target_os = "android",
2753-
target_os = "macos",
2754-
target_os = "freebsd",
2755-
target_os = "redox",
2756-
))]
2757-
{
2758-
(if explicit {
2759-
if is_dir { S_IRWXUGO } else { MODE_RW_UGO }
2760-
} else {
2761-
source_mode & S_IRWXUGO
2762-
}) & !umask
2763-
}
2737+
(if explicit {
2738+
if is_dir { S_IRWXUGO } else { MODE_RW_UGO }
2739+
} else {
2740+
source_mode & S_IRWXUGO
2741+
}) & !umask
27642742
} else {
27652743
source_mode & S_IRWXUGO
27662744
}

tests/by-util/test_cp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7899,7 +7899,7 @@ fn test_cp_existing_no_preserve_dir() {
78997899
scene.cmd("mkdir").arg("d1").succeeds();
79007900
scene.cmd("mkdir").arg("d2").succeeds();
79017901
scene.cmd("chmod").arg("770").arg("d1").succeeds();
7902-
scene.cmd("chmod").arg("700").arg("d2").succeeds();
7902+
scene.cmd("chmod").arg("707").arg("d2").succeeds();
79037903
let d2_mode = at.metadata("d2").mode();
79047904

79057905
scene
@@ -7957,7 +7957,7 @@ fn test_cp_existing_default_dir() {
79577957
scene.cmd("mkdir").arg("d1").succeeds();
79587958
scene.cmd("mkdir").arg("d2").succeeds();
79597959
scene.cmd("chmod").arg("770").arg("d1").succeeds();
7960-
scene.cmd("chmod").arg("700").arg("d2").succeeds();
7960+
scene.cmd("chmod").arg("707").arg("d2").succeeds();
79617961
let d2_mode = at.metadata("d2").mode();
79627962

79637963
scene
@@ -8015,7 +8015,7 @@ fn test_cp_existing_preserve_dir() {
80158015
scene.cmd("mkdir").arg("d1").succeeds();
80168016
scene.cmd("mkdir").arg("d2").succeeds();
80178017
scene.cmd("chmod").arg("770").arg("d1").succeeds();
8018-
scene.cmd("chmod").arg("700").arg("d2").succeeds();
8018+
scene.cmd("chmod").arg("707").arg("d2").succeeds();
80198019
let d1_mode = at.metadata("d1").mode();
80208020

80218021
scene

0 commit comments

Comments
 (0)