mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
address comment
This commit is contained in:
parent
6cb0d5ad7d
commit
78e1eae1ef
1 changed files with 47 additions and 44 deletions
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue