- match file_descriptor.as_file_handle() {
- Ok(FileHandle { file, writable }) => {
- // We sync the file if it was opened in a mode different than read-only.
- if *writable {
- // `File::sync_all` does the checks that are done when closing a file. We do this to
- // to handle possible errors correctly.
- let result = this.try_unwrap_io_result(file.sync_all().map(|_| 0i32));
- // Now we actually close the file.
- drop(file);
- // And return the result.
- result
- } else {
- // We drop the file, this closes it but ignores any errors produced when closing
- // it. This is done because `File::sync_all` cannot be done over files like
- // `/dev/urandom` which are read-only. Check
- // https://github.com/rust-lang/miri/issues/999#issuecomment-568920439 for a deeper
- // discussion.
- drop(file);
- Ok(0)
- }
- },
- Err(_) => this.handle_not_found()
+ let FileHandle { file, writable } = file_descriptor.as_file_handle()?;
+ // We sync the file if it was opened in a mode different than read-only.
+ if *writable {
+ // `File::sync_all` does the checks that are done when closing a file. We do this to
+ // to handle possible errors correctly.
+ let result = this.try_unwrap_io_result(file.sync_all().map(|_| 0i32));
+ // Now we actually close the file.
+ drop(file);
+ // And return the result.
+ result
+ } else {
+ // We drop the file, this closes it but ignores any errors produced when closing
+ // it. This is done because `File::sync_all` cannot be done over files like
+ // `/dev/urandom` which are read-only. Check
+ // https://github.com/rust-lang/miri/issues/999#issuecomment-568920439 for a deeper
+ // discussion.
+ drop(file);
+ Ok(0)