use std::path::Path;
use anyhow::Result;
#[allow(clippy::len_without_is_empty)]
pub trait FileIo
where
Self: Sized + Send + Sync + std::fmt::Debug,
{
fn open(path: &Path) -> Result<Self>;
fn open_existing(path: &Path) -> Result<Self>;
fn read_at(&self, offset: u64, buf: &mut [u8]) -> Result<()>;
fn write_at(&mut self, offset: u64, data: &[u8]) -> Result<()>;
fn sync(&mut self) -> Result<()>;
fn len(&self) -> Result<u64>;
fn set_len(&mut self, len: u64) -> Result<()>;
}
pub mod simple_file;
pub(crate) fn sync_dir(dir: &Path) -> Result<()> {
use anyhow::Context;
std::fs::File::open(dir)
.and_then(|f| f.sync_all())
.with_context(|| format!("Failed to fsync directory {}", dir.display()))?;
Ok(())
}