From 84d20ba60fdbf624f0edd8756464f96fcb3eedcd Mon Sep 17 00:00:00 2001 From: rajajisai Date: Sun, 24 Aug 2025 18:45:46 -0400 Subject: [PATCH 1/2] Use F_FULLSYNC in darwin based operating systems --- core/io/unix.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core/io/unix.rs b/core/io/unix.rs index e10f7f3ec..5877fa194 100644 --- a/core/io/unix.rs +++ b/core/io/unix.rs @@ -259,12 +259,24 @@ impl File for UnixFile { #[instrument(err, skip_all, level = Level::TRACE)] fn sync(&self, c: Completion) -> Result { let file = self.file.lock(); - let result = unsafe { libc::fsync(file.as_raw_fd()) }; + + #[cfg(not(any(target_os = "macos", target_os = "ios")))] + let result = libc::fsync(file.as_raw_fd()); + + #[cfg(any(target_os = "macos", target_os = "ios"))] + let result = unsafe { libc::fcntl(file.as_raw_fd(), libc::F_FULLFSYNC) }; + if result == -1 { let e = std::io::Error::last_os_error(); Err(e.into()) } else { + + #[cfg(not(any(target_os = "macos", target_os = "ios")))] trace!("fsync"); + + #[cfg(any(target_os = "macos", target_os = "ios"))] + trace!("fcntl(F_FULLSYNC)"); + c.complete(0); Ok(c) } From 9068a2938057433f39f93f9ac6f6ac4a7d75dbac Mon Sep 17 00:00:00 2001 From: rajajisai Date: Sun, 24 Aug 2025 18:56:05 -0400 Subject: [PATCH 2/2] Use unsafe block --- core/io/unix.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/core/io/unix.rs b/core/io/unix.rs index 5877fa194..b7567b683 100644 --- a/core/io/unix.rs +++ b/core/io/unix.rs @@ -260,11 +260,19 @@ impl File for UnixFile { fn sync(&self, c: Completion) -> Result { let file = self.file.lock(); - #[cfg(not(any(target_os = "macos", target_os = "ios")))] - let result = libc::fsync(file.as_raw_fd()); - - #[cfg(any(target_os = "macos", target_os = "ios"))] - let result = unsafe { libc::fcntl(file.as_raw_fd(), libc::F_FULLFSYNC) }; + let result = unsafe { + + #[cfg(not(any(target_os = "macos", target_os = "ios")))] + { + libc::fsync(file.as_raw_fd()) + } + + #[cfg(any(target_os = "macos", target_os = "ios"))] + { + libc::fcntl(file.as_raw_fd(), libc::F_FULLFSYNC) + } + + }; if result == -1 { let e = std::io::Error::last_os_error();