recusrive dir processing okay

work
Avril 4 years ago
parent edc40681b9
commit 10fa018cdf
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -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)

@ -58,10 +58,8 @@ fn install() -> eyre::Result<()>
Ok(())
}
/// Process a path for deletion
///
/// Currently a mock impl
async fn process(state: Arc<state::State>, file: String)
/// Currently a mock impl for process
async fn process_mock(state: Arc<state::State>, file: String)
{
let config = state.config();
let _g = state.lock().await;
@ -76,6 +74,14 @@ async fn process(state: Arc<state::State>, file: String)
.with_suggestion(|| "Are you sure this database location is correct"));
}
async fn process(state: Arc<state::State>, 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::Config>
{
config.validate().await

Loading…
Cancel
Save