File tree 2 files changed +24
-8
lines changed 2 files changed +24
-8
lines changed Original file line number Diff line number Diff line change @@ -366,6 +366,28 @@ fn file_lock_blocking_async() {
366
366
t. join ( ) . unwrap ( ) ;
367
367
}
368
368
369
+ #[ test]
370
+ #[ cfg( windows) ]
371
+ fn file_try_lock_async ( ) {
372
+ const FILE_FLAG_OVERLAPPED : u32 = 0x40000000 ;
373
+
374
+ let tmpdir = tmpdir ( ) ;
375
+ let filename = & tmpdir. join ( "file_try_lock_async.txt" ) ;
376
+ let f1 = check ! ( File :: create( filename) ) ;
377
+ let f2 =
378
+ check ! ( OpenOptions :: new( ) . custom_flags( FILE_FLAG_OVERLAPPED ) . write( true ) . open( filename) ) ;
379
+
380
+ // Check that shared locks block exclusive locks
381
+ check ! ( f1. lock_shared( ) ) ;
382
+ assert_matches ! ( f2. try_lock( ) . unwrap_err( ) . kind( ) , ErrorKind :: WouldBlock ) ;
383
+ check ! ( f1. unlock( ) ) ;
384
+
385
+ // Check that exclusive locks block all locks
386
+ check ! ( f1. lock( ) ) ;
387
+ assert_matches ! ( f2. try_lock( ) . unwrap_err( ) . kind( ) , ErrorKind :: WouldBlock ) ;
388
+ assert_matches ! ( f2. try_lock_shared( ) . unwrap_err( ) . kind( ) , ErrorKind :: WouldBlock ) ;
389
+ }
390
+
369
391
#[ test]
370
392
fn file_test_io_seek_shakedown ( ) {
371
393
// 01234567890123
Original file line number Diff line number Diff line change @@ -415,10 +415,7 @@ impl File {
415
415
416
416
match result {
417
417
Ok ( _) => Ok ( ( ) ) ,
418
- Err ( err)
419
- if err. raw_os_error ( ) == Some ( c:: ERROR_IO_PENDING as i32 )
420
- || err. raw_os_error ( ) == Some ( c:: ERROR_LOCK_VIOLATION as i32 ) =>
421
- {
418
+ Err ( err) if err. raw_os_error ( ) == Some ( c:: ERROR_LOCK_VIOLATION as i32 ) => {
422
419
Err ( TryLockError :: WouldBlock )
423
420
}
424
421
Err ( err) => Err ( TryLockError :: Error ( err) ) ,
@@ -440,10 +437,7 @@ impl File {
440
437
441
438
match result {
442
439
Ok ( _) => Ok ( ( ) ) ,
443
- Err ( err)
444
- if err. raw_os_error ( ) == Some ( c:: ERROR_IO_PENDING as i32 )
445
- || err. raw_os_error ( ) == Some ( c:: ERROR_LOCK_VIOLATION as i32 ) =>
446
- {
440
+ Err ( err) if err. raw_os_error ( ) == Some ( c:: ERROR_LOCK_VIOLATION as i32 ) => {
447
441
Err ( TryLockError :: WouldBlock )
448
442
}
449
443
Err ( err) => Err ( TryLockError :: Error ( err) ) ,
You can’t perform that action at this time.
0 commit comments