| use std::path::PathBuf; |
|
|
| use derive_setters::Setters; |
|
|
| |
| #[derive(Debug, Clone, Setters)] |
| #[setters(strip_option, into)] |
| pub struct Walker { |
| |
| pub cwd: PathBuf, |
| |
| pub max_depth: Option<usize>, |
| |
| pub max_breadth: Option<usize>, |
| |
| pub max_file_size: Option<u64>, |
| |
| pub max_files: Option<usize>, |
| |
| pub max_total_size: Option<u64>, |
| |
| pub skip_binary: bool, |
| } |
|
|
| impl Walker { |
| |
| pub fn conservative() -> Self { |
| Self { |
| cwd: PathBuf::new(), |
| max_depth: Some(5), |
| max_breadth: Some(10), |
| max_file_size: Some(1024 * 1024), |
| max_files: Some(100), |
| max_total_size: Some(10 * 1024 * 1024), |
| skip_binary: true, |
| } |
| } |
|
|
| |
| pub fn unlimited() -> Self { |
| Self { |
| cwd: PathBuf::new(), |
| max_depth: None, |
| max_breadth: None, |
| max_file_size: None, |
| max_files: None, |
| max_total_size: None, |
| skip_binary: false, |
| } |
| } |
| } |
|
|
| impl Default for Walker { |
| fn default() -> Self { |
| Self::conservative() |
| } |
| } |
|
|
| |
| #[derive(Clone, Debug, PartialEq, Eq)] |
| pub struct WalkedFile { |
| |
| pub path: String, |
| |
| pub file_name: Option<String>, |
| |
| pub size: u64, |
| } |
|
|
| impl WalkedFile { |
| |
| pub fn is_dir(&self) -> bool { |
| self.path.ends_with('/') |
| } |
| } |
|
|