@@ -367,26 +367,16 @@ impl File {
367
367
Ok ( _) => Ok ( ( ) ) ,
368
368
Err ( err) => {
369
369
if err. raw_os_error ( ) == Some ( c:: ERROR_IO_PENDING as i32 ) {
370
- // Wait for the lock to be acquired. This can happen asynchronously,
371
- // if the file handle was opened for async IO
372
- let wait_result = c:: WaitForSingleObject ( overlapped. hEvent , c:: INFINITE ) ;
373
- if wait_result == c:: WAIT_OBJECT_0 {
374
- // Wait completed successfully, get the lock operation status
375
- let mut bytes_transferred = 0 ;
376
- cvt ( c:: GetOverlappedResult (
377
- self . handle . as_raw_handle ( ) ,
378
- & mut overlapped,
379
- & mut bytes_transferred,
380
- c:: TRUE ,
381
- ) )
382
- . map ( |_| ( ) )
383
- } else if wait_result == c:: WAIT_FAILED {
384
- // Wait failed
385
- Err ( io:: Error :: last_os_error ( ) )
386
- } else {
387
- // WAIT_ABANDONED and WAIT_TIMEOUT should not be possible
388
- unreachable ! ( )
389
- }
370
+ // Wait for the lock to be acquired, and get the lock operation status.
371
+ // This can happen asynchronously, if the file handle was opened for async IO
372
+ let mut bytes_transferred = 0 ;
373
+ cvt ( c:: GetOverlappedResult (
374
+ self . handle . as_raw_handle ( ) ,
375
+ & mut overlapped,
376
+ & mut bytes_transferred,
377
+ c:: TRUE ,
378
+ ) )
379
+ . map ( |_| ( ) )
390
380
} else {
391
381
Err ( err)
392
382
}
@@ -418,15 +408,16 @@ impl File {
418
408
)
419
409
} ) ;
420
410
421
- if let Err ( ref err) = result {
422
- if err. raw_os_error ( ) == Some ( c:: ERROR_IO_PENDING as i32 )
423
- || err. raw_os_error ( ) == Some ( c:: ERROR_LOCK_VIOLATION as i32 )
411
+ match result {
412
+ Ok ( _) => Ok ( true ) ,
413
+ Err ( err)
414
+ if err. raw_os_error ( ) == Some ( c:: ERROR_IO_PENDING as i32 )
415
+ || err. raw_os_error ( ) == Some ( c:: ERROR_LOCK_VIOLATION as i32 ) =>
424
416
{
425
- return Ok ( false ) ;
417
+ Ok ( false )
426
418
}
419
+ Err ( err) => Err ( err) ,
427
420
}
428
- result?;
429
- Ok ( true )
430
421
}
431
422
432
423
pub fn try_lock_shared ( & self ) -> io:: Result < bool > {
@@ -442,15 +433,16 @@ impl File {
442
433
)
443
434
} ) ;
444
435
445
- if let Err ( ref err) = result {
446
- if err. raw_os_error ( ) == Some ( c:: ERROR_IO_PENDING as i32 )
447
- || err. raw_os_error ( ) == Some ( c:: ERROR_LOCK_VIOLATION as i32 )
436
+ match result {
437
+ Ok ( _) => Ok ( true ) ,
438
+ Err ( err)
439
+ if err. raw_os_error ( ) == Some ( c:: ERROR_IO_PENDING as i32 )
440
+ || err. raw_os_error ( ) == Some ( c:: ERROR_LOCK_VIOLATION as i32 ) =>
448
441
{
449
- return Ok ( false ) ;
442
+ Ok ( false )
450
443
}
444
+ Err ( err) => Err ( err) ,
451
445
}
452
- result?;
453
- Ok ( true )
454
446
}
455
447
456
448
pub fn unlock ( & self ) -> io:: Result < ( ) > {
0 commit comments