diff options
Diffstat (limited to 'sys/nixpkgs/pkgs/lf-make-map/src/generator/mod.rs')
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/src/generator/mod.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/sys/nixpkgs/pkgs/lf-make-map/src/generator/mod.rs b/sys/nixpkgs/pkgs/lf-make-map/src/generator/mod.rs new file mode 100644 index 00000000..48df027f --- /dev/null +++ b/sys/nixpkgs/pkgs/lf-make-map/src/generator/mod.rs @@ -0,0 +1,45 @@ +use std::path::PathBuf; + +use anyhow::{Context, Result}; +use log::{debug, info, trace}; +use walkdir::{DirEntry, WalkDir}; + +use crate::mapping::{map_tree::MappingTree, Mapping}; + +pub struct MappingsGenerator { + mappings: MappingTree, + paths_to_process: Vec<PathBuf>, +} + +fn is_dir(entry: &DirEntry) -> bool { + entry.file_type().is_dir() +} + +impl MappingsGenerator { + pub async fn new( + directories_to_scan: Vec<PathBuf>, + max_depth: usize, + home_path: PathBuf, + ) -> Result<Self> { + let mut mappings = MappingTree::new(); + + for dir in directories_to_scan { + for dir2 in WalkDir::new(&dir) + .max_depth(max_depth) + .into_iter() + .filter_entry(|e| is_dir(e)) + { + let directory = + dir2.with_context(|| format!("Failed to read dir ('{}')", &dir.display()))?; + + trace!("Processed '{}'..", directory.path().display()); + + let mapping = Mapping::new(&home_path, directory.path().to_path_buf()); + mappings + .insert(&mapping.key.clone(), mapping) + .context("Failed to insert a key")?; + } + } + todo!() + } +} |