From d414967b79aed56ee6f7bc8b81490c5d300c3a9d Mon Sep 17 00:00:00 2001 From: Daniel Rainer Date: Fri, 17 Oct 2025 02:10:44 +0200 Subject: [PATCH] stdlib: use `fchown` from stdlib instead of `libc` Part of #11964 --- src/fs.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index 80ccc13ba..caa94113c 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -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()) {