Skip to content

Commit b6405e9

Browse files
committed
Change panic on seeking busy file to error.
1 parent 9d9488d commit b6405e9

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

tokio/src/fs/file.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,12 @@ impl AsyncSeek for File {
567567

568568
loop {
569569
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+
}
571576
Idle(ref mut buf_cell) => {
572577
let mut buf = buf_cell.take().unwrap();
573578

tokio/src/fs/file/tests.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,3 +955,24 @@ fn partial_read_set_len_ok() {
955955
assert_eq!(n, FOO.len());
956956
assert_eq!(&buf[..n], FOO);
957957
}
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+
}

0 commit comments

Comments
 (0)