diff --git a/proxmox/src/tools/fs.rs b/proxmox/src/tools/fs.rs index 29233ddf..8e7550a3 100644 --- a/proxmox/src/tools/fs.rs +++ b/proxmox/src/tools/fs.rs @@ -184,7 +184,10 @@ pub fn replace_file>( 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>( })?; 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, + ) + } } }