Skip to content

Commit

Permalink
fix: correctly exclude provided files and folders to exclude
Browse files Browse the repository at this point in the history
  • Loading branch information
kyluke mcdougall committed Oct 8, 2024
1 parent 22ae0e6 commit 8b09dc1
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/path/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ 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,
Some(s) => remove_dot_slash(s),
None => return,
};

if exclude.contains(&path_str.to_string()) {
if must_exclude(exclude, path_str) {
return;
}

if path.is_dir() {
if path_str.starts_with('.') {
if !path_str.starts_with("./") && path_str.starts_with('.') && path_str != "." {
return;
}

Expand All @@ -40,7 +40,7 @@ fn collect_files(path: &Path, files: &mut Vec<Files>, exclude: &[String]) {
}
}
} else if path.is_file() {
if exclude.contains(&path_str.to_string()) {
if must_exclude(exclude, path_str) {
return;
}
if let Ok(content) = fs::read_to_string(path) {
Expand All @@ -51,3 +51,14 @@ fn collect_files(path: &Path, files: &mut Vec<Files>, exclude: &[String]) {
}
}
}

fn must_exclude(exclude: &[String], path: &str) -> bool {
if exclude.contains(&path.to_string()) {
return true;
}
return false;
}

fn remove_dot_slash(path: &str) -> &str {
path.strip_prefix("./").unwrap_or(path)
}

0 comments on commit 8b09dc1

Please sign in to comment.