aboutsummaryrefslogtreecommitdiff
path: root/src/file_finder.rs
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2025-04-05 14:43:19 +0200
committerRuben Beltran del Rio <git@r.bdr.sh>2025-04-05 14:43:19 +0200
commit93c0e8ecee430883c62120f9f0b6999acfac4435 (patch)
tree785b9275d9dd525889bfb8cb687a41260ae39b16 /src/file_finder.rs
parentbb3ec6b31f3c709fbf9f2a12c1708d63a61892ff (diff)
Update, panic less and propagate errors
Diffstat (limited to 'src/file_finder.rs')
-rw-r--r--src/file_finder.rs26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/file_finder.rs b/src/file_finder.rs
index ef57950..08e86c4 100644
--- a/src/file_finder.rs
+++ b/src/file_finder.rs
@@ -9,18 +9,20 @@ pub fn find_files(directory_path: &PathBuf) -> Vec<File> {
fn find_files_recursively(root_path: &PathBuf, directory_path: &PathBuf) -> Vec<File> {
let mut result: Vec<File> = vec![];
let file_handler = FileHandler::default();
- let entries = read_dir(directory_path).unwrap();
- for entry in entries {
- let path = entry.unwrap().path();
- let relative_path = path.strip_prefix(root_path).unwrap();
- if relative_path.starts_with(".git") || relative_path.starts_with(".gitignore") {
- continue;
- }
- if path.is_dir() {
- result.append(&mut find_files_recursively(root_path, &path));
- } else {
- let file_type = file_handler.identify(&path);
- result.push(File { path, file_type });
+ if let Ok(entries) = read_dir(directory_path) {
+ for entry in entries.flatten() {
+ let path = entry.path();
+ if let Ok(relative_path) = path.strip_prefix(root_path) {
+ if relative_path.starts_with(".git") || relative_path.starts_with(".gitignore") {
+ continue;
+ }
+ if path.is_dir() {
+ result.append(&mut find_files_recursively(root_path, &path));
+ } else {
+ let file_type = file_handler.identify(&path);
+ result.push(File { path, file_type });
+ }
+ }
}
}
result