mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
fix-5327
This commit is contained in:
parent
718a527e9b
commit
6c30a1df78
1 changed files with 40 additions and 19 deletions
|
@ -184,7 +184,7 @@ pub struct Attributes {
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub enum Preserve {
|
pub enum Preserve {
|
||||||
No,
|
No { explicit: bool },
|
||||||
Yes { required: bool },
|
Yes { required: bool },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,9 +197,9 @@ impl PartialOrd for Preserve {
|
||||||
impl Ord for Preserve {
|
impl Ord for Preserve {
|
||||||
fn cmp(&self, other: &Self) -> Ordering {
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
match (self, other) {
|
match (self, other) {
|
||||||
(Self::No, Self::No) => Ordering::Equal,
|
(Self::No { .. }, Self::No { .. }) => Ordering::Equal,
|
||||||
(Self::Yes { .. }, Self::No) => Ordering::Greater,
|
(Self::Yes { .. }, Self::No { .. }) => Ordering::Greater,
|
||||||
(Self::No, Self::Yes { .. }) => Ordering::Less,
|
(Self::No { .. }, Self::Yes { .. }) => Ordering::Less,
|
||||||
(
|
(
|
||||||
Self::Yes { required: req_self },
|
Self::Yes { required: req_self },
|
||||||
Self::Yes {
|
Self::Yes {
|
||||||
|
@ -800,7 +800,7 @@ impl Attributes {
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "feat_selinux"))]
|
#[cfg(not(feature = "feat_selinux"))]
|
||||||
{
|
{
|
||||||
Preserve::No
|
Preserve::No { explicit: false }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
links: Preserve::Yes { required: true },
|
links: Preserve::Yes { required: true },
|
||||||
|
@ -809,12 +809,12 @@ impl Attributes {
|
||||||
|
|
||||||
pub const NONE: Self = Self {
|
pub const NONE: Self = Self {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
ownership: Preserve::No,
|
ownership: Preserve::No { explicit: false },
|
||||||
mode: Preserve::No,
|
mode: Preserve::No { explicit: false },
|
||||||
timestamps: Preserve::No,
|
timestamps: Preserve::No { explicit: false },
|
||||||
context: Preserve::No,
|
context: Preserve::No { explicit: false },
|
||||||
links: Preserve::No,
|
links: Preserve::No { explicit: false },
|
||||||
xattr: Preserve::No,
|
xattr: Preserve::No { explicit: false },
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: ownership is required if the user is root, for non-root users it's not required.
|
// 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 {
|
if attribute_strs.len() > 0 {
|
||||||
let no_preserve_attributes = Attributes::parse_iter(attribute_strs)?;
|
let no_preserve_attributes = Attributes::parse_iter(attribute_strs)?;
|
||||||
if matches!(no_preserve_attributes.links, Preserve::Yes { .. }) {
|
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 {
|
fn preserve_hard_links(&self) -> bool {
|
||||||
match self.attributes.links {
|
match self.attributes.links {
|
||||||
Preserve::No => false,
|
Preserve::No { .. } => false,
|
||||||
Preserve::Yes { .. } => true,
|
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.
|
/// Whether to force overwriting the destination file.
|
||||||
fn force(&self) -> bool {
|
fn force(&self) -> bool {
|
||||||
matches!(self.overwrite, OverwriteMode::Clobber(ClobberMode::Force))
|
matches!(self.overwrite, OverwriteMode::Clobber(ClobberMode::Force))
|
||||||
|
@ -1306,7 +1318,7 @@ impl OverwriteMode {
|
||||||
/// If it's required, then the error is thrown.
|
/// If it's required, then the error is thrown.
|
||||||
fn handle_preserve<F: Fn() -> CopyResult<()>>(p: &Preserve, f: F) -> CopyResult<()> {
|
fn handle_preserve<F: Fn() -> CopyResult<()>>(p: &Preserve, f: F) -> CopyResult<()> {
|
||||||
match p {
|
match p {
|
||||||
Preserve::No => {}
|
Preserve::No { .. } => {}
|
||||||
Preserve::Yes { required } => {
|
Preserve::Yes { required } => {
|
||||||
let result = f();
|
let result = f();
|
||||||
if *required {
|
if *required {
|
||||||
|
@ -1735,15 +1747,24 @@ fn copy_file(
|
||||||
let mut permissions = source_metadata.permissions();
|
let mut permissions = source_metadata.permissions();
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
use uucore::mode::get_umask;
|
|
||||||
|
|
||||||
let mut mode = permissions.mode();
|
let mut mode = permissions.mode();
|
||||||
|
|
||||||
// remove sticky bit, suid and gid bit
|
let (is_preserve_mode, is_explicit_no_preserve_mode) = options.preserve_mode();
|
||||||
const SPECIAL_PERMS_MASK: u32 = 0o7000;
|
if !is_preserve_mode {
|
||||||
mode &= !SPECIAL_PERMS_MASK;
|
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
|
// apply umask
|
||||||
|
use uucore::mode::get_umask;
|
||||||
mode &= !get_umask();
|
mode &= !get_umask();
|
||||||
|
|
||||||
permissions.set_mode(mode);
|
permissions.set_mode(mode);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue