1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

cp: fix cp -dR --no-preserve=links d c should have different inodes (#5320)

* fix issue 5308
This commit is contained in:
tommady 2023-09-27 19:16:10 +08:00 committed by GitHub
parent df584f6368
commit 2789885648
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 15 deletions

View file

@ -931,23 +931,33 @@ impl Options {
}; };
// Parse attributes to preserve // Parse attributes to preserve
let attributes = if let Some(attribute_strs) = matches.get_many::<String>(options::PRESERVE) let mut attributes =
{ if let Some(attribute_strs) = matches.get_many::<String>(options::PRESERVE) {
if attribute_strs.len() == 0 { if attribute_strs.len() == 0 {
Attributes::DEFAULT
} else {
Attributes::parse_iter(attribute_strs)?
}
} else if matches.get_flag(options::ARCHIVE) {
// --archive is used. Same as --preserve=all
Attributes::ALL
} else if matches.get_flag(options::NO_DEREFERENCE_PRESERVE_LINKS) {
Attributes::LINKS
} else if matches.get_flag(options::PRESERVE_DEFAULT_ATTRIBUTES) {
Attributes::DEFAULT Attributes::DEFAULT
} else { } else {
Attributes::parse_iter(attribute_strs)? Attributes::NONE
};
// handling no-preserve options and adjusting the attributes
if let Some(attribute_strs) = matches.get_many::<String>(options::NO_PRESERVE) {
if attribute_strs.len() > 0 {
let no_preserve_attributes = Attributes::parse_iter(attribute_strs)?;
if matches!(no_preserve_attributes.links, Preserve::Yes { .. }) {
attributes.links = Preserve::No;
}
} }
} else if matches.get_flag(options::ARCHIVE) { }
// --archive is used. Same as --preserve=all
Attributes::ALL
} else if matches.get_flag(options::NO_DEREFERENCE_PRESERVE_LINKS) {
Attributes::LINKS
} else if matches.get_flag(options::PRESERVE_DEFAULT_ATTRIBUTES) {
Attributes::DEFAULT
} else {
Attributes::NONE
};
#[cfg(not(feature = "feat_selinux"))] #[cfg(not(feature = "feat_selinux"))]
if let Preserve::Yes { required } = attributes.context { if let Preserve::Yes { required } = attributes.context {

View file

@ -1494,7 +1494,7 @@ fn test_cp_preserve_links_case_5() {
let metadata_a = std::fs::metadata(at.subdir.join("c").join("a")).unwrap(); let metadata_a = std::fs::metadata(at.subdir.join("c").join("a")).unwrap();
let metadata_b = std::fs::metadata(at.subdir.join("c").join("b")).unwrap(); let metadata_b = std::fs::metadata(at.subdir.join("c").join("b")).unwrap();
assert_eq!(metadata_a.ino(), metadata_b.ino()); assert_ne!(metadata_a.ino(), metadata_b.ino());
} }
} }