Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions src/uu/cp/src/cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1708,20 +1708,30 @@ pub(crate) fn copy_attributes(

let dest_uid = source_metadata.uid();
let dest_gid = source_metadata.gid();
// gnu compatibility: cp doesn't report an error if it fails to set the ownership.
let _ = wrap_chown(
dest,
&dest
.symlink_metadata()
.map_err(|e| CpError::IoErrContext(e, context.to_owned()))?,
Some(dest_uid),
Some(dest_gid),
false,
Verbosity {
groups_only: false,
level: VerbosityLevel::Silent,
},
);
let meta = &dest
.symlink_metadata()
.map_err(|e| CpError::IoErrContext(e, context.to_owned()))?;

let try_chown = {
|uid| {
wrap_chown(
dest,
meta,
uid,
Some(dest_gid),
false,
Verbosity {
groups_only: false,
level: VerbosityLevel::Silent,
},
)
}
};
// gnu compatibility: cp doesn't report an error if it fails to set the ownership,
// and will fall back to changing only the gid if possible.
if try_chown(Some(dest_uid)).is_err() {
let _ = try_chown(None);
}
Ok(())
})?;

Expand Down
Loading