Skip to content

Commit

Permalink
cp: refactor should_preserve_attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
shinhs0506 committed May 11, 2023
1 parent b323ea2 commit 0776a08
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0776a08

Please sign in to comment.