Skip to content

Commit

Permalink
fs: fix build and test errors (#69)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
BraulioVM authored Dec 31, 2021
1 parent fda1639 commit 4807d0e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Inner {
self.uring.submission().sync();
return Ok(());
}
Err(ref e) if e.kind() == io::ErrorKind::Other => {
Err(ref e) if e.raw_os_error() == Some(libc::EBUSY) => {
self.tick();
}
Err(e) => {
Expand Down
4 changes: 4 additions & 0 deletions src/driver/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ pub(crate) struct Op<T: 'static> {
pub(crate) struct Completion<T> {
pub(crate) data: T,
pub(crate) result: io::Result<u32>,
#[cfg_attr(
not(test), // the field is currently only read in tests
allow(dead_code)
)]
pub(crate) flags: u32,
}

Expand Down
6 changes: 4 additions & 2 deletions src/fs/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ use std::path::Path;
///
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// tokio_uring::start(async {
/// remove_dir("/some/dir")?;
/// });
/// remove_dir("/some/dir").await?;
/// Ok::<(), std::io::Error>(())
/// })?;
/// Ok(())
/// }
/// ```
pub async fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
Expand Down
8 changes: 5 additions & 3 deletions src/fs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,14 @@ impl fmt::Debug for File {
/// # Examples
///
/// ```no_run
/// use tokio_uring::fs::remove_dir;
/// use tokio_uring::fs::remove_file;
///
/// fn main() -> Result<(), Box<dyn std::error::Error>> {
/// tokio_uring::start(async {
/// remove_file("/some/file.txt")?;
/// });
/// remove_file("/some/file.txt").await?;
/// Ok::<(), std::io::Error>(())
/// })?;
/// Ok(())
/// }
/// ```
pub async fn remove_file<P: AsRef<Path>>(path: P) -> io::Result<()> {
Expand Down
3 changes: 1 addition & 2 deletions tests/fs_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,12 @@ async fn poll_once(future: impl std::future::Future) {

fn assert_invalid_fd(fd: RawFd) {
use std::fs::File;
use std::io;

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

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

0 comments on commit 4807d0e

Please sign in to comment.