Skip to content

Commit 4807d0e

Browse files
authored
fs: fix build and test errors (#69)
After rust-lang/rust#85746 , `ErrorKind::Other` is not what it used to. This library depended on `ErrorKind::Other` in a couple places for error handling, and that's I believe why the tests were failing. I've changed those bits of error handling to rely on the `raw_os_error` instead. This should be more granular than the `kind`, but also more stable. I believe I've chosen the right error codes that we were supposed to handle, and the tests now pass (in my machine anyway lol). I've also changed a couple doc tests that were failing to compile. After these changes, running `cargo test` succeeds.
1 parent fda1639 commit 4807d0e

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

src/driver/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl Inner {
108108
self.uring.submission().sync();
109109
return Ok(());
110110
}
111-
Err(ref e) if e.kind() == io::ErrorKind::Other => {
111+
Err(ref e) if e.raw_os_error() == Some(libc::EBUSY) => {
112112
self.tick();
113113
}
114114
Err(e) => {

src/driver/op.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ pub(crate) struct Op<T: 'static> {
2525
pub(crate) struct Completion<T> {
2626
pub(crate) data: T,
2727
pub(crate) result: io::Result<u32>,
28+
#[cfg_attr(
29+
not(test), // the field is currently only read in tests
30+
allow(dead_code)
31+
)]
2832
pub(crate) flags: u32,
2933
}
3034

src/fs/directory.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ use std::path::Path;
1212
///
1313
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
1414
/// tokio_uring::start(async {
15-
/// remove_dir("/some/dir")?;
16-
/// });
15+
/// remove_dir("/some/dir").await?;
16+
/// Ok::<(), std::io::Error>(())
17+
/// })?;
18+
/// Ok(())
1719
/// }
1820
/// ```
1921
pub async fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {

src/fs/file.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,14 @@ impl fmt::Debug for File {
349349
/// # Examples
350350
///
351351
/// ```no_run
352-
/// use tokio_uring::fs::remove_dir;
352+
/// use tokio_uring::fs::remove_file;
353353
///
354354
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
355355
/// tokio_uring::start(async {
356-
/// remove_file("/some/file.txt")?;
357-
/// });
356+
/// remove_file("/some/file.txt").await?;
357+
/// Ok::<(), std::io::Error>(())
358+
/// })?;
359+
/// Ok(())
358360
/// }
359361
/// ```
360362
pub async fn remove_file<P: AsRef<Path>>(path: P) -> io::Result<()> {

tests/fs_file.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,12 @@ async fn poll_once(future: impl std::future::Future) {
138138

139139
fn assert_invalid_fd(fd: RawFd) {
140140
use std::fs::File;
141-
use std::io;
142141

143142
let mut f = unsafe { File::from_raw_fd(fd) };
144143
let mut buf = vec![];
145144

146145
match f.read_to_end(&mut buf) {
147-
Err(ref e) if e.kind() == io::ErrorKind::Other => {}
146+
Err(ref e) if e.raw_os_error() == Some(libc::EBADF) => {}
148147
res => panic!("{:?}", res),
149148
}
150149
}

0 commit comments

Comments
 (0)