mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
cp: refactor copy_attributes() function
Create a `copy_attributes()` function to contain the loop that copies each of a specified set of attributes in turn.
This commit is contained in:
parent
2f88ba8628
commit
c370b678b1
1 changed files with 9 additions and 3 deletions
|
@ -1206,6 +1206,14 @@ impl OverwriteMode {
|
|||
}
|
||||
}
|
||||
|
||||
/// Copy the specified attributes from one path to another.
|
||||
fn copy_attributes(source: &Path, dest: &Path, attributes: &[Attribute]) -> CopyResult<()> {
|
||||
for attribute in attributes {
|
||||
copy_attribute(source, dest, attribute)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn copy_attribute(source: &Path, dest: &Path, attribute: &Attribute) -> CopyResult<()> {
|
||||
let context = &*format!("{} -> {}", source.quote(), dest.quote());
|
||||
let source_metadata = fs::symlink_metadata(source).context(context)?;
|
||||
|
@ -1545,9 +1553,7 @@ fn copy_file(
|
|||
// the user does not have permission to write to the file.
|
||||
fs::set_permissions(dest, dest_permissions).ok();
|
||||
}
|
||||
for attribute in &options.preserve_attributes {
|
||||
copy_attribute(source, dest, attribute)?;
|
||||
}
|
||||
copy_attributes(source, dest, &options.preserve_attributes)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue