Skip to content

Commit 48ebaaf

Browse files
committed
add IO::remove_file_async
1 parent eb206ad commit 48ebaaf

3 files changed

Lines changed: 25 additions & 5 deletions

File tree

libsql-wal/src/io/mod.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::io;
21
use std::path::Path;
32
use std::sync::Arc;
3+
use std::{future::Future, io};
44

55
use chrono::{DateTime, Utc};
66
use 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

95101
impl<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

138148
pub struct Inspect<W, F> {

libsql-wal/src/segment/current.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff 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());

libsql-wal/tests/flaky_fs.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff 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

163166
macro_rules! assert_not_corrupt {

0 commit comments

Comments
 (0)