Skip to content

Commit

Permalink
fix: match entire path when excluding
Browse files Browse the repository at this point in the history
  • Loading branch information
kyluke mcdougall committed Oct 8, 2024
1 parent 4422945 commit 22ae0e6
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/path/extract.rs
Original file line number Diff line number Diff line change
@@ -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<String>, exclude: &[String]) -> Option<Vec<Files>> {
let mut files = vec![];
Expand All @@ -20,11 +20,18 @@ pub fn extract_content(path_str: &Option<String>, exclude: &[String]) -> Option<
}

fn collect_files(path: &Path, files: &mut Vec<Files>, 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) {
Expand All @@ -33,13 +40,14 @@ fn collect_files(path: &Path, files: &mut Vec<Files>, 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,
});
}
}
}
}

0 comments on commit 22ae0e6

Please sign in to comment.