mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
Fix cp bug: pre-write permission change (#2769)
This commit is contained in:
parent
d5463ea5b9
commit
a1960f5da0
2 changed files with 15 additions and 3 deletions
|
@ -1292,7 +1292,13 @@ fn copy_file(source: &Path, dest: &Path, options: &Options) -> CopyResult<()> {
|
|||
.map(|meta| !meta.file_type().is_symlink())
|
||||
.unwrap_or(false)
|
||||
{
|
||||
fs::set_permissions(&dest, dest_permissions).unwrap();
|
||||
// Here, to match GNU semantics, we quietly ignore an error
|
||||
// if a user does not have the correct ownership to modify
|
||||
// the permissions of a file.
|
||||
//
|
||||
// FWIW, the OS will throw an error later, on the write op, if
|
||||
// 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)?;
|
||||
|
@ -1312,7 +1318,7 @@ fn copy_helper(source: &Path, dest: &Path, options: &Options, context: &str) ->
|
|||
/* workaround a limitation of fs::copy
|
||||
* https://github.com/rust-lang/rust/issues/79390
|
||||
*/
|
||||
File::create(dest)?;
|
||||
File::create(dest).context(dest.display().to_string())?;
|
||||
} else if is_symlink {
|
||||
copy_link(source, dest)?;
|
||||
} else if options.reflink_mode != ReflinkMode::Never {
|
||||
|
|
|
@ -725,6 +725,12 @@ fn test_cp_parents_dest_not_directory() {
|
|||
.stderr_contains("with --parents, the destination must be a directory");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn test_cp_writable_special_file_permissions() {
|
||||
new_ucmd!().arg("/dev/null").arg("/dev/zero").succeeds();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cp_preserve_no_args() {
|
||||
new_ucmd!()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue