]>
Commit | Line | Data |
---|---|---|
1e2d00b6 RBR |
1 | use crate::file_handler::{File, FileHandler}; |
2 | use std::fs::read_dir; | |
3 | use std::path::PathBuf; | |
4 | ||
5 | pub fn find_files(directory_path: PathBuf) -> Vec<File> { | |
5643a041 RBR |
6 | return find_files_recursively(&directory_path, &directory_path); |
7 | } | |
8 | ||
9 | fn find_files_recursively(root_path: &PathBuf, directory_path: &PathBuf) -> Vec<File> { | |
1e2d00b6 RBR |
10 | let mut result: Vec<File> = vec![]; |
11 | let file_handler = FileHandler::default(); | |
5643a041 | 12 | let entries = read_dir(&directory_path).unwrap(); |
1e2d00b6 RBR |
13 | for entry in entries { |
14 | let path = entry.unwrap().path(); | |
5643a041 RBR |
15 | let relative_path = path.strip_prefix(&root_path).unwrap(); |
16 | if relative_path.starts_with(".") && !relative_path.starts_with(".well-known") { | |
1e2d00b6 RBR |
17 | continue; |
18 | } | |
19 | if path.is_dir() { | |
5643a041 | 20 | result.append(&mut find_files_recursively(&root_path, &path)) |
1e2d00b6 RBR |
21 | } else { |
22 | let file_type = file_handler.identify(&path); | |
23 | result.push(File { | |
24 | path: path, | |
25 | file_type: file_type, | |
26 | }); | |
27 | } | |
28 | } | |
29 | return result; | |
30 | } |