From 718a527e9be7dbaf15b7369f2b7650e9729a9e93 Mon Sep 17 00:00:00 2001 From: tommady Date: Sat, 30 Sep 2023 07:09:57 +0000 Subject: [PATCH 01/17] add testcase for no preserve mode --- tests/by-util/test_cp.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 1ce74572d..f6d339a7e 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -1550,6 +1550,32 @@ fn test_cp_preserve_links_case_7() { assert!(at.plus("dest").join("g").exists()); } +#[test] +#[cfg(all(unix, not(target_os = "freebsd")))] +fn test_cp_no_preserve_mode_case() { + use libc::umask; + use uucore::fs as uufs; + let (at, mut ucmd) = at_and_ucmd!(); + + at.touch("a"); + at.set_mode("a", 0o731); + unsafe { umask(0o077) }; + + ucmd.arg("-a") + .arg("--no-preserve=mode") + .arg("a") + .arg("b") + .succeeds(); + + assert!(at.file_exists("b")); + + let metadata_b = std::fs::metadata(at.subdir.join("b")).unwrap(); + let permission_b = uufs::display_permissions(&metadata_b, false); + assert_eq!(permission_b, "rw-------".to_string()); + + unsafe { umask(0o022) }; +} + #[test] // For now, disable the test on Windows. Symlinks aren't well support on Windows. // It works on Unix for now and it works locally when run from a powershell From 6c30a1df78704773257f9f1272b2e0d492a3feec Mon Sep 17 00:00:00 2001 From: tommady Date: Wed, 4 Oct 2023 06:04:46 +0000 Subject: [PATCH 02/17] fix-5327 --- src/uu/cp/src/cp.rs | 59 ++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index b6270719c..285a696a9 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -184,7 +184,7 @@ pub struct Attributes { #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Preserve { - No, + No { explicit: bool }, Yes { required: bool }, } @@ -197,9 +197,9 @@ impl PartialOrd for Preserve { impl Ord for Preserve { fn cmp(&self, other: &Self) -> Ordering { match (self, other) { - (Self::No, Self::No) => Ordering::Equal, - (Self::Yes { .. }, Self::No) => Ordering::Greater, - (Self::No, Self::Yes { .. }) => Ordering::Less, + (Self::No { .. }, Self::No { .. }) => Ordering::Equal, + (Self::Yes { .. }, Self::No { .. }) => Ordering::Greater, + (Self::No { .. }, Self::Yes { .. }) => Ordering::Less, ( Self::Yes { required: req_self }, Self::Yes { @@ -800,7 +800,7 @@ impl Attributes { } #[cfg(not(feature = "feat_selinux"))] { - Preserve::No + Preserve::No { explicit: false } } }, links: Preserve::Yes { required: true }, @@ -809,12 +809,12 @@ impl Attributes { pub const NONE: Self = Self { #[cfg(unix)] - ownership: Preserve::No, - mode: Preserve::No, - timestamps: Preserve::No, - context: Preserve::No, - links: Preserve::No, - xattr: Preserve::No, + ownership: Preserve::No { explicit: false }, + mode: Preserve::No { explicit: false }, + timestamps: Preserve::No { explicit: false }, + context: Preserve::No { explicit: false }, + links: Preserve::No { explicit: false }, + xattr: Preserve::No { explicit: false }, }; // TODO: ownership is required if the user is root, for non-root users it's not required. @@ -954,7 +954,9 @@ impl Options { if attribute_strs.len() > 0 { let no_preserve_attributes = Attributes::parse_iter(attribute_strs)?; if matches!(no_preserve_attributes.links, Preserve::Yes { .. }) { - attributes.links = Preserve::No; + attributes.links = Preserve::No { explicit: true }; + } else if matches!(no_preserve_attributes.mode, Preserve::Yes { .. }) { + attributes.mode = Preserve::No { explicit: true }; } } } @@ -1050,11 +1052,21 @@ impl Options { fn preserve_hard_links(&self) -> bool { match self.attributes.links { - Preserve::No => false, + Preserve::No { .. } => false, Preserve::Yes { .. } => true, } } + fn preserve_mode(&self) -> (bool, bool) { + match self.attributes.mode { + Preserve::No { explicit } => match explicit { + true => (false, true), + false => (false, false), + }, + Preserve::Yes { .. } => (true, false), + } + } + /// Whether to force overwriting the destination file. fn force(&self) -> bool { matches!(self.overwrite, OverwriteMode::Clobber(ClobberMode::Force)) @@ -1306,7 +1318,7 @@ impl OverwriteMode { /// If it's required, then the error is thrown. fn handle_preserve CopyResult<()>>(p: &Preserve, f: F) -> CopyResult<()> { match p { - Preserve::No => {} + Preserve::No { .. } => {} Preserve::Yes { required } => { let result = f(); if *required { @@ -1735,15 +1747,24 @@ fn copy_file( let mut permissions = source_metadata.permissions(); #[cfg(unix)] { - use uucore::mode::get_umask; - let mut mode = permissions.mode(); - // remove sticky bit, suid and gid bit - const SPECIAL_PERMS_MASK: u32 = 0o7000; - mode &= !SPECIAL_PERMS_MASK; + let (is_preserve_mode, is_explicit_no_preserve_mode) = options.preserve_mode(); + if !is_preserve_mode { + use libc::{ + S_IRGRP, S_IROTH, S_IRUSR, S_IRWXG, S_IRWXO, S_IRWXU, S_IWGRP, S_IWOTH, S_IWUSR, + }; + const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; + const S_IRWXUGO: u32 = S_IRWXU | S_IRWXG | S_IRWXO; + + match is_explicit_no_preserve_mode { + true => mode = MODE_RW_UGO, + false => mode &= S_IRWXUGO, + } + } // apply umask + use uucore::mode::get_umask; mode &= !get_umask(); permissions.set_mode(mode); From 88f88e51cc54c8f53dc7d24d59d84508cf1c5fb1 Mon Sep 17 00:00:00 2001 From: tommady Date: Wed, 4 Oct 2023 07:12:25 +0000 Subject: [PATCH 03/17] fix expected , found and spelling errors --- src/uu/cp/src/cp.rs | 8 +++++--- tests/by-util/test_cp.rs | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 285a696a9..fc6332f3b 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -2,7 +2,7 @@ // // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -// spell-checker:ignore (ToDO) copydir ficlone fiemap ftruncate linkgs lstat nlink nlinks pathbuf pwrite reflink strs xattrs symlinked deduplicated advcpmv nushell +// spell-checker:ignore (ToDO) copydir ficlone fiemap ftruncate linkgs lstat nlink nlinks pathbuf pwrite reflink strs xattrs symlinked deduplicated advcpmv nushell IRWXG IRWXO IRWXU IRWXUGO IRWXU IRWXG IRWXO IRWXUGO #![allow(clippy::missing_safety_doc)] #![allow(clippy::extra_unused_lifetimes)] @@ -1057,6 +1057,7 @@ impl Options { } } + #[cfg(unix)] fn preserve_mode(&self) -> (bool, bool) { match self.attributes.mode { Preserve::No { explicit } => match explicit { @@ -1754,8 +1755,9 @@ fn copy_file( use libc::{ S_IRGRP, S_IROTH, S_IRUSR, S_IRWXG, S_IRWXO, S_IRWXU, S_IWGRP, S_IWOTH, S_IWUSR, }; - const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; - const S_IRWXUGO: u32 = S_IRWXU | S_IRWXG | S_IRWXO; + const MODE_RW_UGO: u32 = + (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32; + const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32; match is_explicit_no_preserve_mode { true => mode = MODE_RW_UGO, diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index f6d339a7e..95d130f88 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -2,7 +2,7 @@ // // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. -// spell-checker:ignore (flags) reflink (fs) tmpfs (linux) rlimit Rlim NOFILE clob btrfs ROOTDIR USERDIR procfs outfile +// spell-checker:ignore (flags) reflink (fs) tmpfs (linux) rlimit Rlim NOFILE clob btrfs ROOTDIR USERDIR procfs outfile uufs use crate::common::util::TestScenario; #[cfg(not(windows))] From cdde57608c028a8a678a4b55464589a299bcc4d0 Mon Sep 17 00:00:00 2001 From: tommady Date: Wed, 4 Oct 2023 08:06:30 +0000 Subject: [PATCH 04/17] fix macos mode_t is u16 but other unix platforms are u32 --- src/uu/cp/src/cp.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index fc6332f3b..e0a7984f2 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1755,8 +1755,16 @@ fn copy_file( use libc::{ S_IRGRP, S_IROTH, S_IRUSR, S_IRWXG, S_IRWXO, S_IRWXU, S_IWGRP, S_IWOTH, S_IWUSR, }; + + #[cfg(not(macos))] + const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; + #[cfg(not(macos))] + const S_IRWXUGO: u32 = S_IRWXU | S_IRWXG | S_IRWXO; + + #[cfg(macos)] const MODE_RW_UGO: u32 = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32; + #[cfg(macos)] const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32; match is_explicit_no_preserve_mode { From 74c393974c7c5582d2251a54b68805e5eb1dbf0a Mon Sep 17 00:00:00 2001 From: tommady Date: Wed, 4 Oct 2023 08:17:40 +0000 Subject: [PATCH 05/17] fix android mode_t is u16 but other unix platforms are u32 --- src/uu/cp/src/cp.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index c45436b8d..c3ad34118 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1749,15 +1749,15 @@ fn copy_file( S_IRGRP, S_IROTH, S_IRUSR, S_IRWXG, S_IRWXO, S_IRWXU, S_IWGRP, S_IWOTH, S_IWUSR, }; - #[cfg(not(macos))] + #[cfg(not(any(target_os = "android", target_os = "macos")))] const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; - #[cfg(not(macos))] + #[cfg(not(any(target_os = "android", target_os = "macos")))] const S_IRWXUGO: u32 = S_IRWXU | S_IRWXG | S_IRWXO; - #[cfg(macos)] + #[cfg(any(target_os = "android", target_os = "macos"))] const MODE_RW_UGO: u32 = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32; - #[cfg(macos)] + #[cfg(any(target_os = "android", target_os = "macos"))] const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32; match is_explicit_no_preserve_mode { From 6c05385d77454a2cfe89bd371d3fb2af17b3bfc4 Mon Sep 17 00:00:00 2001 From: tommady Date: Wed, 4 Oct 2023 08:31:07 +0000 Subject: [PATCH 06/17] fix macos-12 mode_t is u16 but other unix platforms are u32 --- src/uu/cp/src/cp.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index c3ad34118..1a9d5059d 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1749,15 +1749,23 @@ fn copy_file( S_IRGRP, S_IROTH, S_IRUSR, S_IRWXG, S_IRWXO, S_IRWXU, S_IWGRP, S_IWOTH, S_IWUSR, }; - #[cfg(not(any(target_os = "android", target_os = "macos")))] + #[cfg(not(any( + target_os = "android", + target_os = "macos", + target_os = "macos-12" + )))] const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; - #[cfg(not(any(target_os = "android", target_os = "macos")))] + #[cfg(not(any( + target_os = "android", + target_os = "macos", + target_os = "macos-12" + )))] const S_IRWXUGO: u32 = S_IRWXU | S_IRWXG | S_IRWXO; - #[cfg(any(target_os = "android", target_os = "macos"))] + #[cfg(any(target_os = "android", target_os = "macos", target_os = "macos-12"))] const MODE_RW_UGO: u32 = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32; - #[cfg(any(target_os = "android", target_os = "macos"))] + #[cfg(any(target_os = "android", target_os = "macos", target_os = "macos-12"))] const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32; match is_explicit_no_preserve_mode { From 5ce372082077bad27f2857979e1a09427f97d921 Mon Sep 17 00:00:00 2001 From: tommady Date: Wed, 4 Oct 2023 09:12:26 +0000 Subject: [PATCH 07/17] fix freebds mode_t is u16 but other unix platforms are u32 --- src/uu/cp/src/cp.rs | 20 ++++++++++++++++---- tests/by-util/test_cp.rs | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 1a9d5059d..f8c5ef3ce 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1752,20 +1752,32 @@ fn copy_file( #[cfg(not(any( target_os = "android", target_os = "macos", - target_os = "macos-12" + target_os = "macos-12", + target_os = "freebds", )))] const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; #[cfg(not(any( target_os = "android", target_os = "macos", - target_os = "macos-12" + target_os = "macos-12", + target_os = "freebds", )))] const S_IRWXUGO: u32 = S_IRWXU | S_IRWXG | S_IRWXO; - #[cfg(any(target_os = "android", target_os = "macos", target_os = "macos-12"))] + #[cfg(any( + target_os = "android", + target_os = "macos", + target_os = "macos-12", + target_os = "freebds", + ))] const MODE_RW_UGO: u32 = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32; - #[cfg(any(target_os = "android", target_os = "macos", target_os = "macos-12"))] + #[cfg(any( + target_os = "android", + target_os = "macos", + target_os = "macos-12", + target_os = "freebds", + ))] const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32; match is_explicit_no_preserve_mode { diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index e85cd0c57..96b47cd43 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -1553,7 +1553,7 @@ fn test_cp_preserve_links_case_7() { } #[test] -#[cfg(all(unix, not(target_os = "freebsd")))] +#[cfg(all(unix))] fn test_cp_no_preserve_mode_case() { use libc::umask; use uucore::fs as uufs; From aaea3b40fba455156bf927746e5076d0de30a686 Mon Sep 17 00:00:00 2001 From: tommady Date: Wed, 4 Oct 2023 09:16:54 +0000 Subject: [PATCH 08/17] fix freebsd typo --- src/uu/cp/src/cp.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index f8c5ef3ce..72431cc12 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1753,14 +1753,14 @@ fn copy_file( target_os = "android", target_os = "macos", target_os = "macos-12", - target_os = "freebds", + target_os = "freebsd", )))] const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; #[cfg(not(any( target_os = "android", target_os = "macos", target_os = "macos-12", - target_os = "freebds", + target_os = "freebsd", )))] const S_IRWXUGO: u32 = S_IRWXU | S_IRWXG | S_IRWXO; @@ -1768,7 +1768,7 @@ fn copy_file( target_os = "android", target_os = "macos", target_os = "macos-12", - target_os = "freebds", + target_os = "freebsd", ))] const MODE_RW_UGO: u32 = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32; @@ -1776,7 +1776,7 @@ fn copy_file( target_os = "android", target_os = "macos", target_os = "macos-12", - target_os = "freebds", + target_os = "freebsd", ))] const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32; From 6cb0d5ad7dceca1193ded89d133047d773c19c4b Mon Sep 17 00:00:00 2001 From: tommady Date: Wed, 11 Oct 2023 07:53:03 +0000 Subject: [PATCH 09/17] add comment for explicit in the Preserve enum --- src/uu/cp/src/cp.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 72431cc12..58c56138e 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -184,6 +184,8 @@ pub struct Attributes { #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Preserve { + // explicit means is the --no-preserve flag is used or not to distinguish out the default value. + // e.g. --no-preserve=mode means mode = No { explicit = true } No { explicit: bool }, Yes { required: bool }, } From 78e1eae1effe8f60bfcbc49f70acbf8a5530f993 Mon Sep 17 00:00:00 2001 From: tommady Date: Wed, 11 Oct 2023 08:29:13 +0000 Subject: [PATCH 10/17] address comment --- src/uu/cp/src/cp.rs | 91 +++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 58c56138e..034cd4b12 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1743,50 +1743,7 @@ fn copy_file( let mut permissions = source_metadata.permissions(); #[cfg(unix)] { - let mut mode = permissions.mode(); - - let (is_preserve_mode, is_explicit_no_preserve_mode) = options.preserve_mode(); - if !is_preserve_mode { - use libc::{ - S_IRGRP, S_IROTH, S_IRUSR, S_IRWXG, S_IRWXO, S_IRWXU, S_IWGRP, S_IWOTH, S_IWUSR, - }; - - #[cfg(not(any( - target_os = "android", - target_os = "macos", - target_os = "macos-12", - target_os = "freebsd", - )))] - const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; - #[cfg(not(any( - target_os = "android", - target_os = "macos", - target_os = "macos-12", - target_os = "freebsd", - )))] - const S_IRWXUGO: u32 = S_IRWXU | S_IRWXG | S_IRWXO; - - #[cfg(any( - target_os = "android", - target_os = "macos", - target_os = "macos-12", - target_os = "freebsd", - ))] - const MODE_RW_UGO: u32 = - (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32; - #[cfg(any( - target_os = "android", - target_os = "macos", - target_os = "macos-12", - target_os = "freebsd", - ))] - const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32; - - match is_explicit_no_preserve_mode { - true => mode = MODE_RW_UGO, - false => mode &= S_IRWXUGO, - } - } + let mut mode = handling_no_preserve_mode(options, permissions.mode()); // apply umask use uucore::mode::get_umask; @@ -1918,6 +1875,52 @@ fn copy_file( Ok(()) } +fn handling_no_preserve_mode(options: &Options, org_mode: u32) -> u32 { + let (is_preserve_mode, is_explicit_no_preserve_mode) = options.preserve_mode(); + if !is_preserve_mode { + use libc::{ + S_IRGRP, S_IROTH, S_IRUSR, S_IRWXG, S_IRWXO, S_IRWXU, S_IWGRP, S_IWOTH, S_IWUSR, + }; + + #[cfg(not(any( + target_os = "android", + target_os = "macos", + target_os = "macos-12", + target_os = "freebsd", + )))] + const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; + #[cfg(not(any( + target_os = "android", + target_os = "macos", + target_os = "macos-12", + target_os = "freebsd", + )))] + const S_IRWXUGO: u32 = S_IRWXU | S_IRWXG | S_IRWXO; + + #[cfg(any( + target_os = "android", + target_os = "macos", + target_os = "macos-12", + target_os = "freebsd", + ))] + const MODE_RW_UGO: u32 = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32; + #[cfg(any( + target_os = "android", + target_os = "macos", + target_os = "macos-12", + target_os = "freebsd", + ))] + const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32; + + match is_explicit_no_preserve_mode { + true => return MODE_RW_UGO, + false => return org_mode & S_IRWXUGO, + }; + } + + org_mode +} + /// Copy the file from `source` to `dest` either using the normal `fs::copy` or a /// copy-on-write scheme if --reflink is specified and the filesystem supports it. fn copy_helper( From c59b0f11fd821254863930ff51328a5bfbeee45f Mon Sep 17 00:00:00 2001 From: tommady Date: Wed, 11 Oct 2023 08:57:04 +0000 Subject: [PATCH 11/17] fix linter --- src/uu/cp/src/cp.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 034cd4b12..b1dd94dbd 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1875,6 +1875,7 @@ fn copy_file( Ok(()) } +#[cfg(unix)] fn handling_no_preserve_mode(options: &Options, org_mode: u32) -> u32 { let (is_preserve_mode, is_explicit_no_preserve_mode) = options.preserve_mode(); if !is_preserve_mode { From 7ea19c7c5dd2f99d8fc4db3e2337f7a9072b715b Mon Sep 17 00:00:00 2001 From: tommady Date: Thu, 12 Oct 2023 10:42:44 +0800 Subject: [PATCH 12/17] Update src/uu/cp/src/cp.rs Co-authored-by: Sylvestre Ledru --- src/uu/cp/src/cp.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index b1dd94dbd..eb14e0904 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1889,14 +1889,10 @@ fn handling_no_preserve_mode(options: &Options, org_mode: u32) -> u32 { target_os = "macos-12", target_os = "freebsd", )))] - const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; - #[cfg(not(any( - target_os = "android", - target_os = "macos", - target_os = "macos-12", - target_os = "freebsd", - )))] - const S_IRWXUGO: u32 = S_IRWXU | S_IRWXG | S_IRWXO; + { + const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; + const S_IRWXUGO: u32 = S_IRWXU | S_IRWXG | S_IRWXO; + } #[cfg(any( target_os = "android", From 9be5583d363972b05c07d6cae95c549665edb519 Mon Sep 17 00:00:00 2001 From: tommady Date: Thu, 12 Oct 2023 10:42:52 +0800 Subject: [PATCH 13/17] Update src/uu/cp/src/cp.rs Co-authored-by: Sylvestre Ledru --- src/uu/cp/src/cp.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index eb14e0904..5df5eaf20 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1900,14 +1900,10 @@ fn handling_no_preserve_mode(options: &Options, org_mode: u32) -> u32 { target_os = "macos-12", target_os = "freebsd", ))] - const MODE_RW_UGO: u32 = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32; - #[cfg(any( - target_os = "android", - target_os = "macos", - target_os = "macos-12", - target_os = "freebsd", - ))] - const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32; + { + const MODE_RW_UGO: u32 = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32; + const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32; + } match is_explicit_no_preserve_mode { true => return MODE_RW_UGO, From c9fa07035b1846fedd3883bdf04dddd7ea8c5e6f Mon Sep 17 00:00:00 2001 From: tommady Date: Thu, 12 Oct 2023 02:52:02 +0000 Subject: [PATCH 14/17] fix linter errors --- src/uu/cp/src/cp.rs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 5df5eaf20..40b485c5c 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1890,8 +1890,12 @@ fn handling_no_preserve_mode(options: &Options, org_mode: u32) -> u32 { target_os = "freebsd", )))] { - const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; + const MODE_RW_UGO: u32 = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; const S_IRWXUGO: u32 = S_IRWXU | S_IRWXG | S_IRWXO; + match is_explicit_no_preserve_mode { + true => return MODE_RW_UGO, + false => return org_mode & S_IRWXUGO, + }; } #[cfg(any( @@ -1901,14 +1905,14 @@ fn handling_no_preserve_mode(options: &Options, org_mode: u32) -> u32 { target_os = "freebsd", ))] { - const MODE_RW_UGO: u32 = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32; + const MODE_RW_UGO: u32 = + (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) as u32; const S_IRWXUGO: u32 = (S_IRWXU | S_IRWXG | S_IRWXO) as u32; - } - - match is_explicit_no_preserve_mode { - true => return MODE_RW_UGO, - false => return org_mode & S_IRWXUGO, - }; + match is_explicit_no_preserve_mode { + true => return MODE_RW_UGO, + false => return org_mode & S_IRWXUGO, + }; + } } org_mode From 9df50096c867ba182d4b0c1b2b520ea9dd4c5a86 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Wed, 25 Oct 2023 10:15:46 +0200 Subject: [PATCH 15/17] cp: remove "all" from cfg; rename test fn --- tests/by-util/test_cp.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 71c3eafb0..a4922f93f 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -1552,8 +1552,8 @@ fn test_cp_preserve_links_case_7() { } #[test] -#[cfg(all(unix))] -fn test_cp_no_preserve_mode_case() { +#[cfg(unix)] +fn test_cp_no_preserve_mode() { use libc::umask; use uucore::fs as uufs; let (at, mut ucmd) = at_and_ucmd!(); From 086f7b548c525d7945f7edacbf1b3e7cea78c659 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Wed, 25 Oct 2023 10:20:01 +0200 Subject: [PATCH 16/17] cp: replace word in comment --- src/uu/cp/src/cp.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 40b485c5c..4240af01f 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -184,7 +184,7 @@ pub struct Attributes { #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Preserve { - // explicit means is the --no-preserve flag is used or not to distinguish out the default value. + // explicit means whether the --no-preserve flag is used or not to distinguish out the default value. // e.g. --no-preserve=mode means mode = No { explicit = true } No { explicit: bool }, Yes { required: bool }, From f8a30d524e1e5bd0c6f80a14293d9ad4ab83b4df Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Wed, 25 Oct 2023 10:43:23 +0200 Subject: [PATCH 17/17] cp: rename handling_no_preserve_mode to handle_no_preserve_mode --- src/uu/cp/src/cp.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 4240af01f..0ceef46e3 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1743,7 +1743,7 @@ fn copy_file( let mut permissions = source_metadata.permissions(); #[cfg(unix)] { - let mut mode = handling_no_preserve_mode(options, permissions.mode()); + let mut mode = handle_no_preserve_mode(options, permissions.mode()); // apply umask use uucore::mode::get_umask; @@ -1876,7 +1876,7 @@ fn copy_file( } #[cfg(unix)] -fn handling_no_preserve_mode(options: &Options, org_mode: u32) -> u32 { +fn handle_no_preserve_mode(options: &Options, org_mode: u32) -> u32 { let (is_preserve_mode, is_explicit_no_preserve_mode) = options.preserve_mode(); if !is_preserve_mode { use libc::{