mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
rust-utils: use exists/rename instead of renameat2
Use exists and rename instead of renameat2 which is only available in the linux implementation of libc. To enable compilation of pvsecret on macos the rust wrapper function renameat2 which calls the libc renameat2 function is replaced with rust native std::fs::exists ad std::fs::rename functions because macos' implementation of libc does not have the renameat2 function. Reviewed-by: Jan Höppner <hoeppner@linux.ibm.com> Reviewed-by: Steffen Eiden <seiden@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:
committed by
Steffen Eiden
parent
c3a84109b7
commit
e894fb61d8
@@ -4,7 +4,7 @@
|
||||
|
||||
use std::{
|
||||
ffi::{CString, OsStr},
|
||||
fs::{File, OpenOptions},
|
||||
fs::{rename, File, OpenOptions},
|
||||
io::{self, Seek, SeekFrom, Write},
|
||||
os::unix::{ffi::OsStrExt, fs::OpenOptionsExt},
|
||||
path::Path,
|
||||
@@ -218,17 +218,16 @@ impl TempPath {
|
||||
}
|
||||
|
||||
fn persist(self, operation: AtomicFileOperation) -> Result<()> {
|
||||
let options = match operation {
|
||||
AtomicFileOperation::Replace => 0,
|
||||
AtomicFileOperation::NoReplace => libc::RENAME_NOREPLACE,
|
||||
};
|
||||
|
||||
renameat2(&self.temp_path, &self.path, options).map_err(|e| {
|
||||
PvCoreError::FileAccessRename {
|
||||
src: self.temp_path.as_ref().to_str().unwrap().to_string(),
|
||||
dst: self.path.as_ref().to_str().unwrap().to_string(),
|
||||
source: e,
|
||||
if let Ok(true) = self.path.try_exists() {
|
||||
if operation == AtomicFileOperation::NoReplace {
|
||||
return Err(Error::Io(io::Error::from(io::ErrorKind::AlreadyExists)));
|
||||
}
|
||||
}
|
||||
|
||||
rename(&self.temp_path, &self.path).map_err(|e| PvCoreError::FileAccessRename {
|
||||
src: self.temp_path.as_ref().to_str().unwrap().to_string(),
|
||||
dst: self.path.as_ref().to_str().unwrap().to_string(),
|
||||
source: e,
|
||||
})?;
|
||||
self.forget();
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user