Skip to content

Commit d602a6b

Browse files
committed
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. Fixes #55920
1 parent a2bbf7d commit d602a6b

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)