@@ -1125,9 +1125,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1125
1125
this. check_no_isolation ( "fsync" ) ?;
1126
1126
1127
1127
let fd = this. read_scalar ( fd_op) ?. to_i32 ( ) ?;
1128
- if let Some ( FileHandle { file, writable : _ } ) = this. machine . file_handler . handles . get_mut ( & fd) {
1129
- let result = file. sync_all ( ) ;
1130
- this. try_unwrap_io_result ( result. map ( |_| 0i32 ) )
1128
+ if let Some ( FileHandle { file, writable } ) = this. machine . file_handler . handles . get_mut ( & fd) {
1129
+ if !* writable && cfg ! ( windows) {
1130
+ // sync_all() will return an error on Windows hosts if the file is not opened for writing.
1131
+ Ok ( 0i32 )
1132
+ } else {
1133
+ let result = file. sync_all ( ) ;
1134
+ this. try_unwrap_io_result ( result. map ( |_| 0i32 ) )
1135
+ }
1131
1136
} else {
1132
1137
this. handle_not_found ( )
1133
1138
}
@@ -1139,9 +1144,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
1139
1144
this. check_no_isolation ( "fdatasync" ) ?;
1140
1145
1141
1146
let fd = this. read_scalar ( fd_op) ?. to_i32 ( ) ?;
1142
- if let Some ( FileHandle { file, writable : _ } ) = this. machine . file_handler . handles . get_mut ( & fd) {
1143
- let result = file. sync_data ( ) ;
1144
- this. try_unwrap_io_result ( result. map ( |_| 0i32 ) )
1147
+ if let Some ( FileHandle { file, writable } ) = this. machine . file_handler . handles . get_mut ( & fd) {
1148
+ if !* writable && cfg ! ( windows) {
1149
+ // sync_data() will return an error on Windows hosts if the file is not opened for writing.
1150
+ Ok ( 0i32 )
1151
+ } else {
1152
+ let result = file. sync_data ( ) ;
1153
+ this. try_unwrap_io_result ( result. map ( |_| 0i32 ) )
1154
+ }
1145
1155
} else {
1146
1156
this. handle_not_found ( )
1147
1157
}
0 commit comments