File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -567,7 +567,12 @@ impl AsyncSeek for File {
567
567
568
568
loop {
569
569
match inner. state {
570
- Busy ( _) => panic ! ( "must wait for poll_complete before calling start_seek" ) ,
570
+ Busy ( _) => {
571
+ return Err ( io:: Error :: new (
572
+ io:: ErrorKind :: Other ,
573
+ "other file operation is pending, call poll_complete before start_seek" ,
574
+ ) )
575
+ }
571
576
Idle ( ref mut buf_cell) => {
572
577
let mut buf = buf_cell. take ( ) . unwrap ( ) ;
573
578
Original file line number Diff line number Diff line change @@ -955,3 +955,24 @@ fn partial_read_set_len_ok() {
955
955
assert_eq ! ( n, FOO . len( ) ) ;
956
956
assert_eq ! ( & buf[ ..n] , FOO ) ;
957
957
}
958
+
959
+ #[ test]
960
+ fn busy_file_seek_error ( ) {
961
+ let mut file = MockFile :: default ( ) ;
962
+ let mut seq = Sequence :: new ( ) ;
963
+ file. expect_inner_write ( )
964
+ . once ( )
965
+ . in_sequence ( & mut seq)
966
+ . returning ( |_| Err ( io:: ErrorKind :: Other . into ( ) ) ) ;
967
+
968
+ let mut file = crate :: io:: BufReader :: new ( File :: from_std ( file) ) ;
969
+ {
970
+ let mut t = task:: spawn ( file. write ( HELLO ) ) ;
971
+ assert_ready_ok ! ( t. poll( ) ) ;
972
+ }
973
+
974
+ pool:: run_one ( ) ;
975
+
976
+ let mut t = task:: spawn ( file. seek ( SeekFrom :: Start ( 0 ) ) ) ;
977
+ assert_ready_err ! ( t. poll( ) ) ;
978
+ }
You can’t perform that action at this time.
0 commit comments