stdlib: use fchown from stdlib instead of libc

Part of #11964
This commit is contained in:
Daniel Rainer
2025-10-17 02:10:44 +02:00
committed by Johannes Altmanninger
parent 448471bd50
commit d414967b79

View File

@@ -9,7 +9,7 @@
},
};
use errno::errno;
use libc::{LOCK_EX, LOCK_SH, c_int, fchown, flock};
use libc::{LOCK_EX, LOCK_SH, c_int, flock};
use nix::{fcntl::OFlag, sys::stat::Mode};
use std::{
ffi::CString,
@@ -314,12 +314,11 @@ fn update_metadata(old_file: &File, new_file: &File) {
// did, it would be tricky to set the permissions correctly. (bash doesn't get this
// case right either).
if let Ok(md) = old_file.metadata() {
// TODO(MSRV): Consider replacing with std::os::unix::fs::fchown when MSRV >= 1.73
if unsafe { fchown(new_file.as_raw_fd(), md.uid(), md.gid()) } == -1 {
if let Err(e) = std::os::unix::fs::fchown(new_file, Some(md.uid()), Some(md.gid())) {
FLOG!(
synced_file_access,
"Error when changing ownership of file:",
errno::errno()
e
);
}
if let Err(e) = new_file.set_permissions(md.permissions()) {