1use std::error::Error;
2use std::fs::File;
3#[cfg(unix)]
4use std::os::unix::io::AsRawFd;
5
6pub trait SyncFilesystem {
7 fn sync_filesystem(&self) -> Result<(), Box<dyn Error>>;
8}
9
10impl SyncFilesystem for File {
11 #[cfg(unix)]
12 fn sync_filesystem(&self) -> Result<(), Box<dyn Error>> {
13 let fd = self.as_raw_fd();
14 unsafe {
15 if nix::libc::syncfs(fd) != 0 {
16 unimplemented!()
17 }
18 }
19 Ok(())
20 }
21
22 #[cfg(target_arch = "wasm32")]
23 fn sync_filesystem(&self) -> Result<(), Box<dyn Error>> {
24 Err(String::from("syncing the filesystem is unsupported for wasm32").into())
25 }
26}