rust-utils: remove unused renameat2 rust wrapper

Remove the unused rust wrapper function renameat2 which calls renameat2
from linux' libc implementation.

Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com>
Signed-off-by: Finn Callies <fcallies@linux.ibm.com>
Signed-off-by: Steffen Eiden <seiden@linux.ibm.com>
This commit is contained in:
Finn Callies
2025-08-12 11:31:20 +02:00
committed by Steffen Eiden
parent e894fb61d8
commit e1d1c6df9c

View File

@@ -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<P: AsRef<Path>, Q: AsRef<Path>>(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,