diff --git a/src/delete.rs b/src/delete.rs index 6419066..73b82cb 100644 --- a/src/delete.rs +++ b/src/delete.rs @@ -27,6 +27,11 @@ use futures::{ async fn process_single(state: Arc, path: impl AsRef) -> eyre::Result<()> { let path = path.as_ref(); + #[cfg(debug_assertions)] { + if !path.is_file() { + panic!("process_single() expected a file, but {:?} is not one.", path); + } + } let _g = state.lock().await; debug!("{:?} Processing", path); Ok(()) @@ -38,6 +43,13 @@ where F: FnMut(fs::DirEntry) -> Fut + Clone + 'static + Send + Sync, T: Send + 'static, Fut: Future + Send + Sync, { + #[cfg(debug_assertions)] { + let path = path.as_ref(); + if !path.is_dir() { + panic!("walk_dir() expected a directory, but {:?} is not one.", path); + } + } + trace!("{:?} Spawning children", path.as_ref()); async move { let se_path = || format!("{:?}", path.as_ref()).header("Path was"); let mut dir = fs::read_dir(&path).await @@ -51,15 +63,16 @@ where F: FnMut(fs::DirEntry) -> Fut + Clone + 'static + Send + Sync, { let path = entry.path(); if path.is_dir() { + workers.push(tokio::spawn(walk_dir(path, output.clone()))); } else if path.is_file() { voutput.push(output(entry).await); } } voutput.extend(future::join_all(workers) - .map(|x| x.into_iter().filter_map(Result::ok).flatten()) - .await - .into_iter() + .map(|x| x.into_iter() + .filter_map(Result::ok).flatten()) + .await.into_iter() .flatten()); Ok(voutput) }.boxed() @@ -73,7 +86,6 @@ pub async fn process(state: Arc, path: impl AsRef) -> eyre:: let path = path.as_ref(); let se_path = || format!("{:?}", path).header("Path was"); if path.is_dir() { - trace!("{:?} Spawning children", path); for res in walk_dir(path.to_owned(), move |file| process_single(Arc::clone(&state), file.path())).await? .into_iter() .filter_map(Result::err) diff --git a/src/main.rs b/src/main.rs index faced7e..dd4e91b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,10 +58,8 @@ fn install() -> eyre::Result<()> Ok(()) } -/// Process a path for deletion -/// -/// Currently a mock impl -async fn process(state: Arc, file: String) +/// Currently a mock impl for process +async fn process_mock(state: Arc, file: String) { let config = state.config(); let _g = state.lock().await; @@ -76,6 +74,14 @@ async fn process(state: Arc, file: String) .with_suggestion(|| "Are you sure this database location is correct")); } +async fn process(state: Arc, file: String) -> eyre::Result<()> +{ + delete::process(state, &file).await + .wrap_err(eyre!("Processing failed")) + .with_section(move || file.header("Path was"))?; + Ok(()) +} + async fn validate_config(config: config::Config) -> eyre::Result { config.validate().await