Use write_and_fsync in save_metadata

This commit is contained in:
Arpad Müller
2023-08-31 14:49:07 +02:00
parent 9cffba255c
commit df28e7afa0
2 changed files with 4 additions and 7 deletions

View File

@@ -9,9 +9,9 @@
//! [`remote_timeline_client`]: super::remote_timeline_client
use std::fs::{File, OpenOptions};
use std::io::{self, Write};
use std::io;
use anyhow::{bail, ensure, Context};
use anyhow::{ensure, Context};
use serde::{de::Error, Deserialize, Serialize, Serializer};
use thiserror::Error;
use tracing::info_span;
@@ -273,10 +273,7 @@ pub async fn save_metadata(
let metadata_bytes = data.to_bytes().context("Failed to get metadata bytes")?;
if file.write(&metadata_bytes)? != metadata_bytes.len() {
bail!("Could not write all the metadata bytes in a single call");
}
file.sync_all()?;
file.write_and_fsync(&metadata_bytes)?;
// fsync the parent directory to ensure the directory entry is durable
if first_save {

View File

@@ -392,7 +392,7 @@ impl VirtualFile {
/// Write the given buffer (which has to be below the kernel's internal page size) and fsync
///
/// This ensures some level of atomicity (not a good one, but it's the best we have).
pub async fn write_and_fsync(&mut self, buf: &[u8]) -> Result<(), Error> {
pub fn write_and_fsync(&mut self, buf: &[u8]) -> Result<(), Error> {
if self.write(buf)? != buf.len() {
return Err(Error::new(
std::io::ErrorKind::Other,