Skip to content

Commit 3bee49f

Browse files
committed
Auto merge of #60121 - davazp:fix-sync-all-macos, r=KodrAus
Fix sync_all on macos/ios `sync_all` should flush all metadata in macos/ios, so it should call `fcntl` with the `F_FULLFSYNC` flag as `sync_data` does. Note that without this `sync_data` performs more flushes than `sync_all` on macos/ios.
2 parents 0550766 + d602a6b commit 3bee49f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/libstd/sys/unix/fs.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,15 @@ impl File {
526526
}
527527

528528
pub fn fsync(&self) -> io::Result<()> {
529-
cvt_r(|| unsafe { libc::fsync(self.0.raw()) })?;
530-
Ok(())
529+
cvt_r(|| unsafe { os_fsync(self.0.raw()) })?;
530+
return Ok(());
531+
532+
#[cfg(any(target_os = "macos", target_os = "ios"))]
533+
unsafe fn os_fsync(fd: c_int) -> c_int {
534+
libc::fcntl(fd, libc::F_FULLFSYNC)
535+
}
536+
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
537+
unsafe fn os_fsync(fd: c_int) -> c_int { libc::fsync(fd) }
531538
}
532539

533540
pub fn datasync(&self) -> io::Result<()> {

0 commit comments

Comments
 (0)