From e1d1c6df9c0d0d9b55ba33398ec6f87f8495974d Mon Sep 17 00:00:00 2001 From: Finn Callies Date: Tue, 12 Aug 2025 11:31:20 +0200 Subject: [PATCH] rust-utils: remove unused renameat2 rust wrapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the unused rust wrapper function renameat2 which calls renameat2 from linux' libc implementation. Reviewed-by: Steffen Eiden Reviewed-by: Jan Höppner Signed-off-by: Finn Callies Signed-off-by: Steffen Eiden --- rust/utils/src/file.rs | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/rust/utils/src/file.rs b/rust/utils/src/file.rs index 8fe5dd30..4014799d 100644 --- a/rust/utils/src/file.rs +++ b/rust/utils/src/file.rs @@ -3,44 +3,15 @@ // Copyright IBM Corp. 2024 use std::{ - ffi::{CString, OsStr}, + ffi::OsStr, fs::{rename, File, OpenOptions}, io::{self, Seek, SeekFrom, Write}, - os::unix::{ffi::OsStrExt, fs::OpenOptionsExt}, + os::unix::fs::OpenOptionsExt, path::Path, }; use pv::{Error, FileAccessErrorType, PvCoreError, Result}; -/// Rust wrapper for `libc::renameat2` -fn renameat2, Q: AsRef>(oldpath: P, newpath: Q, flags: u32) -> io::Result<()> { - let oldpath_cstr = CString::new(oldpath.as_ref().as_os_str().as_bytes())?; - let oldpath_raw = oldpath_cstr.into_raw(); - let newpath_cstr = CString::new(newpath.as_ref().as_os_str().as_bytes())?; - let newpath_raw = newpath_cstr.into_raw(); - unsafe { - // SAFETY: oldpath_raw and newpath_raw are valid CStrings because they were - // generated by the `CString::new` function. - let ret = libc::renameat2( - libc::AT_FDCWD, - oldpath_raw, - libc::AT_FDCWD, - newpath_raw, - flags, - ); - // SAFETY: libc::renameat2 does not modify `newpath_raw` and is - // therefore still valid. - let _ = CString::from_raw(newpath_raw); - // SAFETY: libc::renameat2 does not modify `oldpath_raw` and is - // therefore still valid. - let _ = CString::from_raw(oldpath_raw); - if ret == -1 { - return Err(io::Error::last_os_error()); - } - Ok(()) - } -} - /// This type helps to perform atomic operations by writing to a temporary file /// and renaming it to the actual filename when the [`AtomicFile::finish`] /// function is called. If the [`AtomicFile::finish`] function is never called,