diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-05-06 18:09:03 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-05-06 18:09:03 +0200 |
commit | 5a27c1fff017f73b41267873ecb01da253030e9f (patch) | |
tree | 8d4bb7b95a30968819109a4c1a6624072189d732 /sys/nixpkgs/pkgs/lf-make-map/src/generator | |
parent | feat(pkgs/lf-make-map): Change the key to custom type and add visuals (diff) | |
download | nixos-config-5a27c1fff017f73b41267873ecb01da253030e9f.tar.gz nixos-config-5a27c1fff017f73b41267873ecb01da253030e9f.zip |
feat(pkgs/lf-make-map): Implement all needed details to produce first mappings
The only bug left right know, is that multiple same mappings can be generated because of the ways the types interact with each other.
Diffstat (limited to 'sys/nixpkgs/pkgs/lf-make-map/src/generator')
-rw-r--r-- | sys/nixpkgs/pkgs/lf-make-map/src/generator/mod.rs | 51 |
1 files changed, 0 insertions, 51 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 deleted file mode 100644 index c03b33dc..00000000 --- a/sys/nixpkgs/pkgs/lf-make-map/src/generator/mod.rs +++ /dev/null @@ -1,51 +0,0 @@ -use std::path::PathBuf; - -use anyhow::{Context, Result}; -use log::trace; -use walkdir::{DirEntry, WalkDir}; - -use crate::mapping::{map_tree::MappingTree, MapKey, 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()); - let mapping_key = mapping.key.clone(); - mappings.insert(&mapping_key, mapping).with_context(|| { - format!( - "Failed to insert '{}' for path: '{}'\nMapTree is now: \n{}", - MapKey::display(&mapping_key), - directory.path().display(), - mappings, - ) - })?; - } - } - todo!() - } -} |