From 22ae0e6979431cb24753d243b69dfe82554439b1 Mon Sep 17 00:00:00 2001 From: kyluke mcdougall <=> Date: Tue, 8 Oct 2024 11:35:49 +0200 Subject: [PATCH] fix: match entire path when excluding --- src/path/extract.rs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/path/extract.rs b/src/path/extract.rs index fb4536b..3638e1a 100644 --- a/src/path/extract.rs +++ b/src/path/extract.rs @@ -1,6 +1,6 @@ +use crate::path::model::Files; use std::fs; use std::path::Path; -use crate::path::model::Files; pub fn extract_content(path_str: &Option, exclude: &[String]) -> Option> { let mut files = vec![]; @@ -20,11 +20,18 @@ pub fn extract_content(path_str: &Option, exclude: &[String]) -> Option< } fn collect_files(path: &Path, files: &mut Vec, exclude: &[String]) { + let path_str = match path.to_str() { + Some(s) => s, + None => return, + }; + + if exclude.contains(&path_str.to_string()) { + return; + } + if path.is_dir() { - if let Some(name) = path.file_name().and_then(|n| n.to_str()) { - if name.starts_with('.') || exclude.contains(&name.to_string()) { - return; - } + if path_str.starts_with('.') { + return; } if let Ok(entries) = fs::read_dir(path) { @@ -33,13 +40,14 @@ fn collect_files(path: &Path, files: &mut Vec, exclude: &[String]) { } } } else if path.is_file() { - if let Some(path_str) = path.to_str() { - if let Ok(content) = fs::read_to_string(path) { - files.push(Files { - path: path_str.to_string(), - content, - }); - } + if exclude.contains(&path_str.to_string()) { + return; + } + if let Ok(content) = fs::read_to_string(path) { + files.push(Files { + path: path_str.to_string(), + content, + }); } } -} \ No newline at end of file +}