File tree Expand file tree Collapse file tree 2 files changed +24
-8
lines changed Expand file tree Collapse file tree 2 files changed +24
-8
lines changed Original file line number Diff line number Diff line change @@ -358,6 +358,28 @@ fn file_lock_blocking_async() {
358358 t. join ( ) . unwrap ( ) ;
359359}
360360
361+ #[ test]
362+ #[ cfg( windows) ]
363+ fn file_try_lock_async ( ) {
364+ const FILE_FLAG_OVERLAPPED : u32 = 0x40000000 ;
365+
366+ let tmpdir = tmpdir ( ) ;
367+ let filename = & tmpdir. join ( "file_try_lock_async.txt" ) ;
368+ let f1 = check ! ( File :: create( filename) ) ;
369+ let f2 =
370+ check ! ( OpenOptions :: new( ) . custom_flags( FILE_FLAG_OVERLAPPED ) . write( true ) . open( filename) ) ;
371+
372+ // Check that shared locks block exclusive locks
373+ check ! ( f1. lock_shared( ) ) ;
374+ assert_matches ! ( f2. try_lock( ) . unwrap_err( ) . kind( ) , ErrorKind :: WouldBlock ) ;
375+ check ! ( f1. unlock( ) ) ;
376+
377+ // Check that exclusive locks block all locks
378+ check ! ( f1. lock( ) ) ;
379+ assert_matches ! ( f2. try_lock( ) . unwrap_err( ) . kind( ) , ErrorKind :: WouldBlock ) ;
380+ assert_matches ! ( f2. try_lock_shared( ) . unwrap_err( ) . kind( ) , ErrorKind :: WouldBlock ) ;
381+ }
382+
361383#[ test]
362384fn file_test_io_seek_shakedown ( ) {
363385 // 01234567890123
Original file line number Diff line number Diff line change @@ -414,10 +414,7 @@ impl File {
414414
415415 match result {
416416 Ok ( _) => Ok ( ( ) ) ,
417- Err ( err)
418- if err. raw_os_error ( ) == Some ( c:: ERROR_IO_PENDING as i32 )
419- || err. raw_os_error ( ) == Some ( c:: ERROR_LOCK_VIOLATION as i32 ) =>
420- {
417+ Err ( err) if err. raw_os_error ( ) == Some ( c:: ERROR_LOCK_VIOLATION as i32 ) => {
421418 Err ( io:: ErrorKind :: WouldBlock . into ( ) )
422419 }
423420 Err ( err) => Err ( err) ,
@@ -439,10 +436,7 @@ impl File {
439436
440437 match result {
441438 Ok ( _) => Ok ( ( ) ) ,
442- Err ( err)
443- if err. raw_os_error ( ) == Some ( c:: ERROR_IO_PENDING as i32 )
444- || err. raw_os_error ( ) == Some ( c:: ERROR_LOCK_VIOLATION as i32 ) =>
445- {
439+ Err ( err) if err. raw_os_error ( ) == Some ( c:: ERROR_LOCK_VIOLATION as i32 ) => {
446440 Err ( io:: ErrorKind :: WouldBlock . into ( ) )
447441 }
448442 Err ( err) => Err ( err) ,
You can’t perform that action at this time.
0 commit comments