use crate::{WalkError, WalkItem};
use std::{
collections::VecDeque,
path::{Path, PathBuf},
};
pub mod rev_iter;
pub mod sync_iter;
#[cfg(feature = "tokio")]
pub mod tokio_iter;
#[derive(Clone)]
pub struct WalkPlan {
pub check_list: Vec<PathBuf>,
pub follow_symlinks: bool,
pub depth_first: bool,
pub capacity: usize,
pub threads: usize,
pub reject_when: fn(&WalkItem) -> bool,
pub ignore_when: fn(&WalkItem) -> bool,
pub finish_when: fn(&WalkItem) -> bool,
}
impl Default for WalkPlan {
fn default() -> Self {
Self {
check_list: vec![],
follow_symlinks: false,
depth_first: false,
capacity: 256,
threads: 8,
reject_when: |_| false,
ignore_when: |_| false,
finish_when: |_| false,
}
}
}
impl WalkPlan {
pub fn new<P: AsRef<Path>>(path: P) -> Self {
Self { check_list: vec![path.as_ref().to_path_buf()], ..Default::default() }
}
pub fn roots<I>(roots: I) -> Self
where
I: IntoIterator,
I::Item: AsRef<Path>,
{
Self { check_list: roots.into_iter().map(|p| p.as_ref().to_path_buf()).collect(), ..Default::default() }
}
pub fn breadth_first_search(mut self) -> Self {
self.depth_first = false;
self
}
pub fn depth_first_search(mut self) -> Self {
self.depth_first = true;
self
}
pub fn with_threads(mut self, threads: usize) -> Self {
self.threads = threads;
self
}
pub fn reject_if(mut self, f: fn(&WalkItem) -> bool) -> Self {
self.reject_when = f;
self
}
pub fn ignore_if(mut self, f: fn(&WalkItem) -> bool) -> Self {
self.ignore_when = f;
self
}
pub fn finish_if(mut self, f: fn(&WalkItem) -> bool) -> Self {
self.finish_when = f;
self
}
}