Skip to content

Commit fca4498

Browse files
committed
f Use sync_all rather than libc::fsync
As it iternally does the right thing (tm): call `libc::fsync` on non-macOS UNIXes and `libc::fcntl` with `libc::F_FULLSYNC` set on macOS (as Apple decided to break POSIX to cheat benchmarks).
1 parent 2205780 commit fca4498

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

lightning-persister/src/fs_store.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ use std::path::{Path, PathBuf};
99
use std::sync::atomic::{AtomicUsize, Ordering};
1010
use std::sync::{Arc, Mutex, RwLock};
1111

12-
#[cfg(not(target_os = "windows"))]
13-
use std::os::unix::io::AsRawFd;
14-
1512
#[cfg(target_os = "windows")]
1613
use {std::ffi::OsStr, std::os::windows::ffi::OsStrExt};
1714

@@ -134,9 +131,7 @@ impl KVStore for FilesystemStore {
134131
{
135132
fs::rename(&tmp_file_path, &dest_file_path)?;
136133
let dir_file = fs::OpenOptions::new().read(true).open(&parent_directory)?;
137-
unsafe {
138-
libc::fsync(dir_file.as_raw_fd());
139-
}
134+
dir_file.sync_all()?;
140135
Ok(())
141136
}
142137

@@ -204,15 +199,13 @@ impl KVStore for FilesystemStore {
204199
std::io::Error::new(std::io::ErrorKind::InvalidInput, msg)
205200
})?;
206201
let dir_file = fs::OpenOptions::new().read(true).open(parent_directory)?;
207-
unsafe {
208-
// The above call to `fs::remove_file` corresponds to POSIX `unlink`, whose changes
209-
// to the inode might get cached (and hence possibly lost on crash), depending on
210-
// the target platform and file system.
211-
//
212-
// In order to assert we permanently removed the file in question we therefore
213-
// call `fsync` on the parent directory on platforms that support it,
214-
libc::fsync(dir_file.as_raw_fd());
215-
}
202+
// The above call to `fs::remove_file` corresponds to POSIX `unlink`, whose changes
203+
// to the inode might get cached (and hence possibly lost on crash), depending on
204+
// the target platform and file system.
205+
//
206+
// In order to assert we permanently removed the file in question we therefore
207+
// call `fsync` on the parent directory on platforms that support it,
208+
dir_file.sync_all()?;
216209
}
217210

218211
if dest_file_path.is_file() {

0 commit comments

Comments
 (0)