Skip to content

Commit

Permalink
Auto merge of #60121 - davazp:fix-sync-all-macos, r=KodrAus
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Apr 23, 2019
2 parents 0550766 + d602a6b commit 3bee49f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/libstd/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,15 @@ impl File {
}

pub fn fsync(&self) -> io::Result<()> {
cvt_r(|| unsafe { libc::fsync(self.0.raw()) })?;
Ok(())
cvt_r(|| unsafe { os_fsync(self.0.raw()) })?;
return Ok(());

#[cfg(any(target_os = "macos", target_os = "ios"))]
unsafe fn os_fsync(fd: c_int) -> c_int {
libc::fcntl(fd, libc::F_FULLFSYNC)
}
#[cfg(not(any(target_os = "macos", target_os = "ios")))]
unsafe fn os_fsync(fd: c_int) -> c_int { libc::fsync(fd) }
}

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

0 comments on commit 3bee49f

Please sign in to comment.