File tree Expand file tree Collapse file tree 7 files changed +92
-9
lines changed
Expand file tree Collapse file tree 7 files changed +92
-9
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,23 @@ use crate::runtime::driver::op::Op;
22use std:: io;
33use std:: path:: Path ;
44
5+ /// # Examples
6+ ///
7+ /// ```no_run
8+ /// use tokio_uring::fs::create_dir;
9+ ///
10+ /// fn main() -> Result<(), Box<dyn std::error::Error>> {
11+ /// tokio_uring::start(async {
12+ /// create_dir("/some/dir").await?;
13+ /// Ok::<(), std::io::Error>(())
14+ /// })?;
15+ /// Ok(())
16+ /// }
17+ /// ```
18+ pub async fn create_dir < P : AsRef < Path > > ( path : P ) -> io:: Result < ( ) > {
19+ Op :: make_dir ( path. as_ref ( ) ) ?. await
20+ }
21+
522/// Removes an empty directory.
623///
724/// # Examples
Original file line number Diff line number Diff line change 11//! Filesystem manipulation operations.
22
33mod directory;
4+ pub use directory:: create_dir;
45pub use directory:: remove_dir;
56
67mod file;
Original file line number Diff line number Diff line change 1+ use crate :: runtime:: driver:: op:: { Completable , CqeResult , Op } ;
2+ use crate :: runtime:: CONTEXT ;
3+
4+ use super :: util:: cstr;
5+
6+ use std:: ffi:: CString ;
7+ use std:: io;
8+ use std:: path:: Path ;
9+
10+ /// Create a directory at path relative to the current working directory
11+ /// of the caller's process.
12+ pub ( crate ) struct Mkdir {
13+ pub ( crate ) _path : CString ,
14+ }
15+
16+ impl Op < Mkdir > {
17+ /// Submit a request to create a directory
18+ pub ( crate ) fn make_dir ( path : & Path ) -> io:: Result < Op < Mkdir > > {
19+ use io_uring:: { opcode, types} ;
20+
21+ let _path = cstr ( path) ?;
22+
23+ CONTEXT . with ( |x| {
24+ x. handle ( )
25+ . expect ( "Not in a runtime context" )
26+ . submit_op ( Mkdir { _path } , |mkdir| {
27+ let p_ref = mkdir. _path . as_c_str ( ) . as_ptr ( ) ;
28+
29+ opcode:: MkDirAt :: new ( types:: Fd ( libc:: AT_FDCWD ) , p_ref) . build ( )
30+ } )
31+ } )
32+ }
33+ }
34+
35+ impl Completable for Mkdir {
36+ type Output = io:: Result < ( ) > ;
37+
38+ fn complete ( self , cqe : CqeResult ) -> Self :: Output {
39+ cqe. result . map ( |_| ( ) )
40+ }
41+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ mod connect;
77
88mod fsync;
99
10+ mod mkdir_at;
11+
1012mod noop;
1113pub ( crate ) use noop:: NoOp ;
1214
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ impl Op<Unlink> {
2020 Self :: unlink ( path, 0 )
2121 }
2222
23- /// Submit a request to unlink a specifed path with provided flags.
23+ /// Submit a request to unlink a specified path with provided flags.
2424 pub ( crate ) fn unlink ( path : & Path , flags : i32 ) -> io:: Result < Op < Unlink > > {
2525 use io_uring:: { opcode, types} ;
2626
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ #[ path = "../src/future.rs" ]
2+ #[ allow( warnings) ]
3+ mod future;
4+
5+ use tokio_test:: assert_ok;
6+ use tokio_uring:: fs;
7+
8+ use tempfile:: tempdir;
9+
10+ #[ test]
11+ fn basic_create_dir ( ) {
12+ tokio_uring:: start ( async {
13+ let base_dir = tempdir ( ) . unwrap ( ) ;
14+ let new_dir = base_dir. path ( ) . join ( "foo" ) ;
15+ let new_dir_2 = new_dir. clone ( ) ;
16+
17+ assert_ok ! ( fs:: create_dir( new_dir) . await ) ;
18+
19+ assert ! ( new_dir_2. is_dir( ) ) ;
20+ } ) ;
21+ }
22+
23+ #[ test]
24+ fn basic_remove_dir ( ) {
25+ tokio_uring:: start ( async {
26+ let temp_dir = tempfile:: TempDir :: new ( ) . unwrap ( ) ;
27+ tokio_uring:: fs:: remove_dir ( temp_dir. path ( ) ) . await . unwrap ( ) ;
28+ assert ! ( std:: fs:: metadata( temp_dir. path( ) ) . is_err( ) ) ;
29+ } ) ;
30+ }
You can’t perform that action at this time.
0 commit comments