From 0776a08a3778d5e3ea2027cfaa00fb6de08e377d Mon Sep 17 00:00:00 2001 From: John Shin Date: Wed, 10 May 2023 18:14:19 -0700 Subject: [PATCH] cp: refactor should_preserve_attribute --- src/uu/cp/src/cp.rs | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/uu/cp/src/cp.rs b/src/uu/cp/src/cp.rs index 6b712643efa..642bbcb145f 100644 --- a/src/uu/cp/src/cp.rs +++ b/src/uu/cp/src/cp.rs @@ -1758,23 +1758,25 @@ fn copy_helper( Ok(()) } -#[cfg(not(windows))] fn should_preserve_attribute(options: &Options) -> bool { - matches!(options.attributes.mode, Preserve::Yes { .. }) - || matches!(options.attributes.timestamps, Preserve::Yes { .. }) - || matches!(options.attributes.links, Preserve::Yes { .. }) - || matches!(options.attributes.context, Preserve::Yes { .. }) - || matches!(options.attributes.xattr, Preserve::Yes { .. }) - || matches!(options.attributes.ownership, Preserve::Yes { .. }) -} + let checks = [ + &options.attributes.mode, + &options.attributes.timestamps, + &options.attributes.links, + &options.attributes.context, + &options.attributes.xattr, + ]; -#[cfg(windows)] -fn should_preserve_attribute(options: &Options) -> bool { - matches!(options.attributes.mode, Preserve::Yes { .. }) - || matches!(options.attributes.timestamps, Preserve::Yes { .. }) - || matches!(options.attributes.links, Preserve::Yes { .. }) - || matches!(options.attributes.context, Preserve::Yes { .. }) - || matches!(options.attributes.xattr, Preserve::Yes { .. }) + #[cfg(unix)] + let checks = [ + checks.as_slice(), + [&options.attributes.ownership].as_slice(), + ] + .concat(); + + checks + .iter() + .any(|attr| matches!(attr, Preserve::Yes { .. })) } // "Copies" a FIFO by creating a new one. This workaround is because Rust's