mirror of
https://github.com/rust-lang/rust.git
synced 2026-06-02 06:28:20 +03:00
Finish fixing Windows host support
This commit is contained in:
+24
-8
@@ -379,9 +379,16 @@ fn fcntl(
|
||||
&& cmd == this.eval_libc_i32("F_FULLFSYNC")?
|
||||
{
|
||||
let &[_, _] = check_arg_count(args)?;
|
||||
if let Some(FileHandle { file, writable: _ }) = this.machine.file_handler.handles.get_mut(&fd) {
|
||||
let result = file.sync_all();
|
||||
this.try_unwrap_io_result(result.map(|_| 0i32))
|
||||
if let Some(FileHandle { file, writable }) = this.machine.file_handler.handles.get_mut(&fd) {
|
||||
if !*writable && cfg!(windows) {
|
||||
// sync_all() will return an error on Windows hosts if the file is not opened
|
||||
// for writing. (FlushFileBuffers requires that the file handle have the
|
||||
// GENERIC_WRITE right)
|
||||
Ok(0i32)
|
||||
} else {
|
||||
let result = file.sync_all();
|
||||
this.try_unwrap_io_result(result.map(|_| 0i32))
|
||||
}
|
||||
} else {
|
||||
this.handle_not_found()
|
||||
}
|
||||
@@ -1128,6 +1135,7 @@ fn fsync(&mut self, fd_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
|
||||
if let Some(FileHandle { file, writable }) = this.machine.file_handler.handles.get_mut(&fd) {
|
||||
if !*writable && cfg!(windows) {
|
||||
// sync_all() will return an error on Windows hosts if the file is not opened for writing.
|
||||
// (FlushFileBuffers requires that the file handle have the GENERIC_WRITE right)
|
||||
Ok(0i32)
|
||||
} else {
|
||||
let result = file.sync_all();
|
||||
@@ -1147,6 +1155,7 @@ fn fdatasync(&mut self, fd_op: OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
|
||||
if let Some(FileHandle { file, writable }) = this.machine.file_handler.handles.get_mut(&fd) {
|
||||
if !*writable && cfg!(windows) {
|
||||
// sync_data() will return an error on Windows hosts if the file is not opened for writing.
|
||||
// (FlushFileBuffers requires that the file handle have the GENERIC_WRITE right)
|
||||
Ok(0i32)
|
||||
} else {
|
||||
let result = file.sync_data();
|
||||
@@ -1187,11 +1196,18 @@ fn sync_file_range(
|
||||
return Ok(-1);
|
||||
}
|
||||
|
||||
if let Some(FileHandle { file, writable: _ }) = this.machine.file_handler.handles.get_mut(&fd) {
|
||||
// In the interest of host compatibility, we conservatively ignore
|
||||
// offset, nbytes, and flags, and sync the entire file.
|
||||
let result = file.sync_data();
|
||||
this.try_unwrap_io_result(result.map(|_| 0i32))
|
||||
if let Some(FileHandle { file, writable }) = this.machine.file_handler.handles.get_mut(&fd) {
|
||||
if !*writable && cfg!(windows) {
|
||||
// sync_data() will return an error on Windows hosts if the file is not opened for
|
||||
// writing. (FlushFileBuffers requires that the file handle have the GENERIC_WRITE
|
||||
// right)
|
||||
Ok(0i32)
|
||||
} else {
|
||||
// In the interest of host compatibility, we conservatively ignore
|
||||
// offset, nbytes, and flags, and sync the entire file.
|
||||
let result = file.sync_data();
|
||||
this.try_unwrap_io_result(result.map(|_| 0i32))
|
||||
}
|
||||
} else {
|
||||
this.handle_not_found()
|
||||
}
|
||||
|
||||
@@ -192,6 +192,11 @@ fn test_file_sync() {
|
||||
file.sync_data().unwrap();
|
||||
file.sync_all().unwrap();
|
||||
|
||||
// Test that we can call sync_data and sync_all on a file opened for reading.
|
||||
let file = File::open(&path).unwrap();
|
||||
file.sync_data().unwrap();
|
||||
file.sync_all().unwrap();
|
||||
|
||||
remove_file(&path).unwrap();
|
||||
}
|
||||
|
||||
|
||||
+19
-3
@@ -55,8 +55,8 @@ fn test_sync_file_range() {
|
||||
let bytes = b"Hello, World!\n";
|
||||
file.write(bytes).unwrap();
|
||||
|
||||
// Test calling sync_file_range on a file.
|
||||
let result = unsafe {
|
||||
// Test calling sync_file_range on the file.
|
||||
let result_1 = unsafe {
|
||||
libc::sync_file_range(
|
||||
file.as_raw_fd(),
|
||||
0,
|
||||
@@ -67,8 +67,24 @@ fn test_sync_file_range() {
|
||||
)
|
||||
};
|
||||
drop(file);
|
||||
|
||||
// Test calling sync_file_range on a file opened for reading.
|
||||
let file = File::open(&path).unwrap();
|
||||
let result_2 = unsafe {
|
||||
libc::sync_file_range(
|
||||
file.as_raw_fd(),
|
||||
0,
|
||||
0,
|
||||
libc::SYNC_FILE_RANGE_WAIT_BEFORE
|
||||
| libc::SYNC_FILE_RANGE_WRITE
|
||||
| libc::SYNC_FILE_RANGE_WAIT_AFTER,
|
||||
)
|
||||
};
|
||||
drop(file);
|
||||
|
||||
remove_file(&path).unwrap();
|
||||
assert_eq!(result, 0);
|
||||
assert_eq!(result_1, 0);
|
||||
assert_eq!(result_2, 0);
|
||||
}
|
||||
|
||||
fn test_mutex_libc_init_recursive() {
|
||||
|
||||
Reference in New Issue
Block a user