mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-14 16:12:19 +00:00
proxmox: cleanup files on fsync errors
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
a0cfb9c20d
commit
bdc7e9d145
@ -184,7 +184,10 @@ pub fn replace_file<P: AsRef<Path>>(
|
||||
|
||||
if fsync {
|
||||
// make sure data is on disk
|
||||
nix::unistd::fsync(file.as_raw_fd())?;
|
||||
if let Err(err) = nix::unistd::fsync(file.as_raw_fd()) {
|
||||
let _ = unistd::unlink(&tmp_path);
|
||||
bail!("fsync failed: {}", err);
|
||||
}
|
||||
}
|
||||
|
||||
if let Err(err) = std::fs::rename(&tmp_path, &path) {
|
||||
@ -261,7 +264,14 @@ pub fn atomic_open_or_create_file<P: AsRef<Path>>(
|
||||
})?;
|
||||
if fsync {
|
||||
// make sure the initial_data is on disk
|
||||
nix::unistd::fsync(file.as_raw_fd())?;
|
||||
if let Err(err) = nix::unistd::fsync(file.as_raw_fd()) {
|
||||
let _ = nix::unistd::unlink(&temp_file_name);
|
||||
bail!(
|
||||
"fsync of initial data to {:?} failed - {}",
|
||||
temp_file_name,
|
||||
err,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user