don't crash on weird directories
This commit is contained in:
parent
5bc8eba61d
commit
2b811359f4
1 changed files with 13 additions and 10 deletions
|
@ -30,22 +30,21 @@ impl PartialOrd for FileNode {
|
|||
}
|
||||
}
|
||||
|
||||
#[once(time = 120)]
|
||||
#[once(time = 600)]
|
||||
pub fn get_filetree(
|
||||
initial_dir: &str,
|
||||
exclusion_list: &[String],
|
||||
exclusion_patterns: &[Regex],
|
||||
) -> FileNode {
|
||||
gen_filetree(initial_dir, exclusion_list, exclusion_patterns)
|
||||
gen_filetree(initial_dir, exclusion_list, exclusion_patterns).unwrap()
|
||||
}
|
||||
|
||||
fn gen_filetree(
|
||||
dir_path: &str,
|
||||
exclusion_list: &[String],
|
||||
exclusion_patterns: &[Regex],
|
||||
) -> FileNode {
|
||||
let mut children: Vec<FileNode> = std::fs::read_dir(dir_path)
|
||||
.unwrap()
|
||||
) -> Result<FileNode, std::io::Error> {
|
||||
let mut children: Vec<FileNode> = std::fs::read_dir(dir_path)?
|
||||
.filter_map(Result::ok)
|
||||
.filter_map(|entry| {
|
||||
let entry_path = entry.path();
|
||||
|
@ -69,10 +68,14 @@ fn gen_filetree(
|
|||
exclusion_list,
|
||||
exclusion_patterns,
|
||||
);
|
||||
if children_of_children.is_dir && children_of_children.children.is_empty() {
|
||||
if let Ok(coc) = children_of_children {
|
||||
if coc.is_dir && coc.children.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(children_of_children)
|
||||
Some(coc)
|
||||
}
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -80,7 +83,7 @@ fn gen_filetree(
|
|||
|
||||
children.sort();
|
||||
|
||||
FileNode {
|
||||
Ok(FileNode {
|
||||
name: Path::new(dir_path)
|
||||
.file_name()
|
||||
.unwrap()
|
||||
|
@ -88,7 +91,7 @@ fn gen_filetree(
|
|||
.to_string(),
|
||||
is_dir: true,
|
||||
children,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn excluded(element: &str, exclusion_list: &[String], exclusion_patterns: &[Regex]) -> bool {
|
||||
|
|
Loading…
Reference in a new issue