diff --git a/crates/util/src/fs.rs b/crates/util/src/fs.rs index e221a64..67490c4 100644 --- a/crates/util/src/fs.rs +++ b/crates/util/src/fs.rs @@ -1,7 +1,6 @@ use std::path::Path; use crate::ResultExt; -use futures::TryStreamExt; use tokio::fs; use tokio_stream::{wrappers::ReadDirStream, StreamExt}; @@ -10,25 +9,20 @@ pub async fn remove_matching(dir: &Path, predicate: F) -> std::io::Result<()> where F: Fn(&Path) -> bool, { - ReadDirStream::new(fs::read_dir(dir).await?) - .try_filter_map(move |entry| { - let predicate = |e| predicate(e); - async move { - let path = entry.path(); - if predicate(path.as_path()) { - if let Ok(metadata) = fs::metadata(&path).await { - if metadata.is_file() { - fs::remove_file(&path).await?; - } else { - fs::remove_dir_all(&path).await?; - } - } - Ok(Some(())) + let mut entries = fs::read_dir(dir).await?; + + while let Some(entry) = entries.next_entry().await? { + let entry_path = entry.path(); + if predicate(entry_path.as_path()) { + if let Ok(metadata) = fs::metadata(&entry_path).await { + if metadata.is_file() { + fs::remove_file(&entry_path).await?; } else { - Ok(None) + fs::remove_dir_all(&entry_path).await?; } } - }) - .try_collect::<()>() - .await + } + } + + Ok(()) }