1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 03:57:44 +00:00

address comment

This commit is contained in:
tommady 2023-10-11 08:29:13 +00:00
parent 6cb0d5ad7d
commit 78e1eae1ef
No known key found for this signature in database
GPG key ID: 175B664929DF2F2F

View file

@ -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(