From f84637b89d363f873b97f7f1a3af45f3eebce142 Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Fri, 25 Feb 2022 13:13:20 -0700 Subject: [PATCH] improve data sync reliability to underlying storage medium --- patch-db/src/store.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/patch-db/src/store.rs b/patch-db/src/store.rs index 8bbeeab..f89d0aa 100644 --- a/patch-db/src/store.rs +++ b/patch-db/src/store.rs @@ -83,8 +83,7 @@ impl Store { backup_file.flush()?; backup_file.sync_all()?; std::fs::rename(&bak_tmp, &bak)?; - nix::unistd::ftruncate(std::os::unix::io::AsRawFd::as_raw_fd(&*f), 0) - .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?; + f.set_len(0)?; serde_cbor::to_writer(&mut *f, &revision)?; serde_cbor::to_writer(&mut *f, &data)?; f.flush()?; @@ -187,7 +186,7 @@ impl Store { async fn sync_to_disk(file: &mut File, patch_bin: &[u8]) -> Result<(), IOError> { file.write_all(patch_bin).await?; file.flush().await?; - file.sync_data().await?; + file.sync_all().await?; Ok(()) } if let Err(e) = sync_to_disk(&mut *self.file, &patch_bin).await {