feat: make task post-hooks stateful (#3454)

This commit is contained in:
sxyazi 2025-12-24 01:15:18 +08:00
parent 329c5d28f0
commit 6e3c96289e
No known key found for this signature in database
12 changed files with 165 additions and 85 deletions

View file

@ -126,11 +126,12 @@ pub trait Provider: Sized {
}
}
fn remove_dir_clean(&self) -> impl Future<Output = ()> {
fn remove_dir_clean(&self) -> impl Future<Output = io::Result<()>> {
let root = self.url().to_owned();
async move {
let mut stack = vec![(root, false)];
let mut result = Ok(());
while let Some((dir, visited)) = stack.pop() {
let Ok(provider) = Self::new(dir.as_url()).await else {
@ -138,7 +139,7 @@ pub trait Provider: Sized {
};
if visited {
provider.remove_dir().await.ok();
result = provider.remove_dir().await;
} else if let Ok(mut it) = provider.read_dir().await {
stack.push((dir, true));
while let Ok(Some(ent)) = it.next().await {
@ -148,6 +149,7 @@ pub trait Provider: Sized {
}
}
}
result
}
}