diff --git a/src/shims/fs.rs b/src/shims/fs.rs index ac405138f52..66e191e3ed4 100644 --- a/src/shims/fs.rs +++ b/src/shims/fs.rs @@ -378,9 +378,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx } else if this.tcx.sess.target.target.target_os == "macos" && cmd == this.eval_libc_i32("F_FULLFSYNC")? { - // On macOS, fsync does not wait for the underlying disk to finish writing, while this - // F_FULLFSYNC operation does. The standard library uses F_FULLFSYNC for both - // File::sync_data() and File::sync_all(). let &[_, _] = check_arg_count(args)?; if let Some(FileHandle { file, writable: _ }) = this.machine.file_handler.handles.get_mut(&fd) { let result = file.sync_all(); @@ -1118,6 +1115,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx } fn fsync(&mut self, fd_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> { + // On macOS, `fsync` (unlike `fcntl(F_FULLFSYNC)`) does not wait for the + // underlying disk to finish writing. In the interest of host compatibility, + // we conservatively implement this with `sync_all`, which + // *does* wait for the disk. + let this = self.eval_context_mut(); this.check_no_isolation("fsync")?; diff --git a/tests/run-pass/libc.rs b/tests/run-pass/libc.rs index 5897c46f637..08199c1452d 100644 --- a/tests/run-pass/libc.rs +++ b/tests/run-pass/libc.rs @@ -47,10 +47,10 @@ fn test_sync_file_range() { use std::os::unix::io::AsRawFd; let path = tmp().join("miri_test_libc_sync_file_range.txt"); - // Cleanup before test + // Cleanup before test. remove_file(&path).ok(); - // Write to a file + // Write to a file. let mut file = File::create(&path).unwrap(); let bytes = b"Hello, World!\n"; file.write(bytes).unwrap();