-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a `create_dir` function call to `tokio_uring::fs` and partially fixes #48. I also renamed `tests/directory.rs` to `tests/fs_directory.rs` so the name is in sync with that of `tests/fs_file.rs`.
- Loading branch information
Kai Mast
authored
Dec 17, 2022
1 parent
3ba9bd8
commit d649652
Showing
7 changed files
with
92 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use crate::runtime::driver::op::{Completable, CqeResult, Op}; | ||
use crate::runtime::CONTEXT; | ||
|
||
use super::util::cstr; | ||
|
||
use std::ffi::CString; | ||
use std::io; | ||
use std::path::Path; | ||
|
||
/// Create a directory at path relative to the current working directory | ||
/// of the caller's process. | ||
pub(crate) struct Mkdir { | ||
pub(crate) _path: CString, | ||
} | ||
|
||
impl Op<Mkdir> { | ||
/// Submit a request to create a directory | ||
pub(crate) fn make_dir(path: &Path) -> io::Result<Op<Mkdir>> { | ||
use io_uring::{opcode, types}; | ||
|
||
let _path = cstr(path)?; | ||
|
||
CONTEXT.with(|x| { | ||
x.handle() | ||
.expect("Not in a runtime context") | ||
.submit_op(Mkdir { _path }, |mkdir| { | ||
let p_ref = mkdir._path.as_c_str().as_ptr(); | ||
|
||
opcode::MkDirAt::new(types::Fd(libc::AT_FDCWD), p_ref).build() | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
impl Completable for Mkdir { | ||
type Output = io::Result<()>; | ||
|
||
fn complete(self, cqe: CqeResult) -> Self::Output { | ||
cqe.result.map(|_| ()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ mod connect; | |
|
||
mod fsync; | ||
|
||
mod mkdir_at; | ||
|
||
mod noop; | ||
pub(crate) use noop::NoOp; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#[path = "../src/future.rs"] | ||
#[allow(warnings)] | ||
mod future; | ||
|
||
use tokio_test::assert_ok; | ||
use tokio_uring::fs; | ||
|
||
use tempfile::tempdir; | ||
|
||
#[test] | ||
fn basic_create_dir() { | ||
tokio_uring::start(async { | ||
let base_dir = tempdir().unwrap(); | ||
let new_dir = base_dir.path().join("foo"); | ||
let new_dir_2 = new_dir.clone(); | ||
|
||
assert_ok!(fs::create_dir(new_dir).await); | ||
|
||
assert!(new_dir_2.is_dir()); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn basic_remove_dir() { | ||
tokio_uring::start(async { | ||
let temp_dir = tempfile::TempDir::new().unwrap(); | ||
tokio_uring::fs::remove_dir(temp_dir.path()).await.unwrap(); | ||
assert!(std::fs::metadata(temp_dir.path()).is_err()); | ||
}); | ||
} |