|
|
@ -27,6 +27,11 @@ use futures::{
|
|
|
|
async fn process_single(state: Arc<state::State>, path: impl AsRef<Path>) -> eyre::Result<()>
|
|
|
|
async fn process_single(state: Arc<state::State>, path: impl AsRef<Path>) -> eyre::Result<()>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let path = path.as_ref();
|
|
|
|
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;
|
|
|
|
let _g = state.lock().await;
|
|
|
|
debug!("{:?} Processing", path);
|
|
|
|
debug!("{:?} Processing", path);
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
@ -38,6 +43,13 @@ where F: FnMut(fs::DirEntry) -> Fut + Clone + 'static + Send + Sync,
|
|
|
|
T: Send + 'static,
|
|
|
|
T: Send + 'static,
|
|
|
|
Fut: Future<Output= T> + Send + Sync,
|
|
|
|
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 {
|
|
|
|
async move {
|
|
|
|
let se_path = || format!("{:?}", path.as_ref()).header("Path was");
|
|
|
|
let se_path = || format!("{:?}", path.as_ref()).header("Path was");
|
|
|
|
let mut dir = fs::read_dir(&path).await
|
|
|
|
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();
|
|
|
|
let path = entry.path();
|
|
|
|
if path.is_dir() {
|
|
|
|
if path.is_dir() {
|
|
|
|
|
|
|
|
|
|
|
|
workers.push(tokio::spawn(walk_dir(path, output.clone())));
|
|
|
|
workers.push(tokio::spawn(walk_dir(path, output.clone())));
|
|
|
|
} else if path.is_file() {
|
|
|
|
} else if path.is_file() {
|
|
|
|
voutput.push(output(entry).await);
|
|
|
|
voutput.push(output(entry).await);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
voutput.extend(future::join_all(workers)
|
|
|
|
voutput.extend(future::join_all(workers)
|
|
|
|
.map(|x| x.into_iter().filter_map(Result::ok).flatten())
|
|
|
|
.map(|x| x.into_iter()
|
|
|
|
.await
|
|
|
|
.filter_map(Result::ok).flatten())
|
|
|
|
.into_iter()
|
|
|
|
.await.into_iter()
|
|
|
|
.flatten());
|
|
|
|
.flatten());
|
|
|
|
Ok(voutput)
|
|
|
|
Ok(voutput)
|
|
|
|
}.boxed()
|
|
|
|
}.boxed()
|
|
|
@ -73,7 +86,6 @@ pub async fn process(state: Arc<state::State>, path: impl AsRef<Path>) -> eyre::
|
|
|
|
let path = path.as_ref();
|
|
|
|
let path = path.as_ref();
|
|
|
|
let se_path = || format!("{:?}", path).header("Path was");
|
|
|
|
let se_path = || format!("{:?}", path).header("Path was");
|
|
|
|
if path.is_dir() {
|
|
|
|
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?
|
|
|
|
for res in walk_dir(path.to_owned(), move |file| process_single(Arc::clone(&state), file.path())).await?
|
|
|
|
.into_iter()
|
|
|
|
.into_iter()
|
|
|
|
.filter_map(Result::err)
|
|
|
|
.filter_map(Result::err)
|
|
|
|