Skip to content

Commit d65a05e

Browse files
committed
refactor(cp): simplify mode consts
1 parent 7382202 commit d65a05e

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
@@ -831,7 +831,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
831831
// We follow it here by setting it to permit all user modes, and passing the original down
832832
// functions such that it is used when creating new dir/file and not preserving mode.
833833
#[cfg(unix)]
834-
let orig_umask = unsafe { libc::umask(!0o700) as u32 };
834+
let orig_umask = unsafe { libc::umask(!libc::S_IRWXU) as u32 };
835835

836836
if let Err(error) = copy(
837837
&sources,
@@ -2724,33 +2724,11 @@ fn handle_created_mode(mode: Preserve, is_dir: bool, source_mode: u32, umask: u3
27242724
const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32;
27252725

27262726
if let Preserve::No { explicit } = mode {
2727-
#[cfg(not(any(
2728-
target_os = "android",
2729-
target_os = "macos",
2730-
target_os = "freebsd",
2731-
target_os = "redox",
2732-
)))]
2733-
{
2734-
(if explicit {
2735-
if is_dir { S_IRWXUGO } else { MODE_RW_UGO }
2736-
} else {
2737-
source_mode & S_IRWXUGO
2738-
}) & !umask
2739-
}
2740-
2741-
#[cfg(any(
2742-
target_os = "android",
2743-
target_os = "macos",
2744-
target_os = "freebsd",
2745-
target_os = "redox",
2746-
))]
2747-
{
2748-
(if explicit {
2749-
if is_dir { S_IRWXUGO } else { MODE_RW_UGO }
2750-
} else {
2751-
source_mode & S_IRWXUGO
2752-
}) & !umask
2753-
}
2727+
(if explicit {
2728+
if is_dir { S_IRWXUGO } else { MODE_RW_UGO }
2729+
} else {
2730+
source_mode & S_IRWXUGO
2731+
}) & !umask
27542732
} else {
27552733
source_mode & S_IRWXUGO
27562734
}

tests/by-util/test_cp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7714,7 +7714,7 @@ fn test_cp_existing_no_preserve_dir() {
77147714
scene.cmd("mkdir").arg("d1").succeeds();
77157715
scene.cmd("mkdir").arg("d2").succeeds();
77167716
scene.cmd("chmod").arg("770").arg("d1").succeeds();
7717-
scene.cmd("chmod").arg("700").arg("d2").succeeds();
7717+
scene.cmd("chmod").arg("707").arg("d2").succeeds();
77187718
let d2_mode = at.metadata("d2").mode();
77197719

77207720
scene
@@ -7772,7 +7772,7 @@ fn test_cp_existing_default_dir() {
77727772
scene.cmd("mkdir").arg("d1").succeeds();
77737773
scene.cmd("mkdir").arg("d2").succeeds();
77747774
scene.cmd("chmod").arg("770").arg("d1").succeeds();
7775-
scene.cmd("chmod").arg("700").arg("d2").succeeds();
7775+
scene.cmd("chmod").arg("707").arg("d2").succeeds();
77767776
let d2_mode = at.metadata("d2").mode();
77777777

77787778
scene
@@ -7830,7 +7830,7 @@ fn test_cp_existing_preserve_dir() {
78307830
scene.cmd("mkdir").arg("d1").succeeds();
78317831
scene.cmd("mkdir").arg("d2").succeeds();
78327832
scene.cmd("chmod").arg("770").arg("d1").succeeds();
7833-
scene.cmd("chmod").arg("700").arg("d2").succeeds();
7833+
scene.cmd("chmod").arg("707").arg("d2").succeeds();
78347834
let d1_mode = at.metadata("d1").mode();
78357835

78367836
scene

0 commit comments

Comments
 (0)