File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- use std:: io;
21use std:: path:: Path ;
32use std:: sync:: Arc ;
3+ use std:: { future:: Future , io} ;
44
55use chrono:: { DateTime , Utc } ;
66use rand:: { rngs:: ThreadRng , thread_rng, Rng } ;
@@ -40,6 +40,8 @@ pub trait Io: Send + Sync + 'static {
4040 Uuid :: from_u128 ( n)
4141 } )
4242 }
43+
44+ fn remove_file_async ( & self , path : & Path ) -> impl Future < Output = io:: Result < ( ) > > + Send ;
4345}
4446
4547#[ derive( Default , Debug , Clone , Copy ) ]
@@ -90,6 +92,10 @@ impl Io for StdIO {
9092 {
9193 f ( & mut thread_rng ( ) )
9294 }
95+
96+ async fn remove_file_async ( & self , path : & Path ) -> io:: Result < ( ) > {
97+ tokio:: fs:: remove_file ( path) . await
98+ }
9399}
94100
95101impl < T : Io > Io for Arc < T > {
@@ -133,6 +139,10 @@ impl<T: Io> Io for Arc<T> {
133139 {
134140 self . as_ref ( ) . with_rng ( f)
135141 }
142+
143+ async fn remove_file_async ( & self , path : & Path ) -> io:: Result < ( ) > {
144+ self . as_ref ( ) . remove_file_async ( path) . await
145+ }
136146}
137147
138148pub struct Inspect < W , F > {
Original file line number Diff line number Diff line change @@ -1015,6 +1015,13 @@ mod test {
10151015 {
10161016 f ( & mut rand:: thread_rng ( ) )
10171017 }
1018+
1019+ fn remove_file_async (
1020+ & self ,
1021+ path : & std:: path:: Path ,
1022+ ) -> impl std:: future:: Future < Output = io:: Result < ( ) > > + Send {
1023+ async move { std:: fs:: remove_file ( path) }
1024+ }
10181025 }
10191026
10201027 let tmp = Arc :: new ( tempdir ( ) . unwrap ( ) ) ;
Original file line number Diff line number Diff line change @@ -144,10 +144,6 @@ impl Io for FlakyIo {
144144 todo ! ( )
145145 }
146146
147- fn uuid ( & self ) -> uuid:: Uuid {
148- todo ! ( )
149- }
150-
151147 fn hard_link ( & self , _src : & Path , _dst : & Path ) -> std:: io:: Result < ( ) > {
152148 todo ! ( )
153149 }
@@ -158,6 +154,13 @@ impl Io for FlakyIo {
158154 {
159155 f ( & mut self . rng . lock ( ) )
160156 }
157+
158+ fn remove_file_async (
159+ & self ,
160+ path : & Path ,
161+ ) -> impl std:: future:: Future < Output = std:: io:: Result < ( ) > > + Send {
162+ async move { self . with_random_failure ( || std:: fs:: remove_file ( path) ) }
163+ }
161164}
162165
163166macro_rules! assert_not_corrupt {
You can’t perform that action at this time.
0 commit comments