mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2026-01-16 02:01:05 +00:00
cp: fail when trying to copy to read only file on mac (#5261)
* cp: fail when trying to copy to read only file * fix spelling error in macos.rs * simplify permissions check * add comment * fix typo
This commit is contained in:
parent
c5a0aa92f8
commit
252d01ac33
2 changed files with 25 additions and 2 deletions
|
|
@ -63,8 +63,15 @@ pub(crate) fn copy_on_write(
|
|||
{
|
||||
// clonefile(2) fails if the destination exists. Remove it and try again. Do not
|
||||
// bother to check if removal worked because we're going to try to clone again.
|
||||
let _ = fs::remove_file(dest);
|
||||
error = pfn(src.as_ptr(), dst.as_ptr(), 0);
|
||||
// first lets make sure the dest file is not read only
|
||||
if fs::metadata(dest).map_or(false, |md| !md.permissions().readonly()) {
|
||||
// remove and copy again
|
||||
// TODO: rewrite this to better match linux behavior
|
||||
// linux first opens the source file and destination file then uses the file
|
||||
// descriptors to do the clone.
|
||||
let _ = fs::remove_file(dest);
|
||||
error = pfn(src.as_ptr(), dst.as_ptr(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue