|
|
|
@ -27,6 +27,11 @@ use futures::{
|
|
|
|
|
async fn process_single(state: Arc<state::State>, path: impl AsRef<Path>) -> 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<Output= T> + 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<state::State>, path: impl AsRef<Path>) -> 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)
|
|
|
|
|