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(
|
pub fn get_filetree(
|
||||||
initial_dir: &str,
|
initial_dir: &str,
|
||||||
exclusion_list: &[String],
|
exclusion_list: &[String],
|
||||||
exclusion_patterns: &[Regex],
|
exclusion_patterns: &[Regex],
|
||||||
) -> FileNode {
|
) -> FileNode {
|
||||||
gen_filetree(initial_dir, exclusion_list, exclusion_patterns)
|
gen_filetree(initial_dir, exclusion_list, exclusion_patterns).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_filetree(
|
fn gen_filetree(
|
||||||
dir_path: &str,
|
dir_path: &str,
|
||||||
exclusion_list: &[String],
|
exclusion_list: &[String],
|
||||||
exclusion_patterns: &[Regex],
|
exclusion_patterns: &[Regex],
|
||||||
) -> FileNode {
|
) -> Result<FileNode, std::io::Error> {
|
||||||
let mut children: Vec<FileNode> = std::fs::read_dir(dir_path)
|
let mut children: Vec<FileNode> = std::fs::read_dir(dir_path)?
|
||||||
.unwrap()
|
|
||||||
.filter_map(Result::ok)
|
.filter_map(Result::ok)
|
||||||
.filter_map(|entry| {
|
.filter_map(|entry| {
|
||||||
let entry_path = entry.path();
|
let entry_path = entry.path();
|
||||||
|
@ -69,10 +68,14 @@ fn gen_filetree(
|
||||||
exclusion_list,
|
exclusion_list,
|
||||||
exclusion_patterns,
|
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
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(children_of_children)
|
Some(coc)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -80,7 +83,7 @@ fn gen_filetree(
|
||||||
|
|
||||||
children.sort();
|
children.sort();
|
||||||
|
|
||||||
FileNode {
|
Ok(FileNode {
|
||||||
name: Path::new(dir_path)
|
name: Path::new(dir_path)
|
||||||
.file_name()
|
.file_name()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -88,7 +91,7 @@ fn gen_filetree(
|
||||||
.to_string(),
|
.to_string(),
|
||||||
is_dir: true,
|
is_dir: true,
|
||||||
children,
|
children,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn excluded(element: &str, exclusion_list: &[String], exclusion_patterns: &[Regex]) -> bool {
|
pub fn excluded(element: &str, exclusion_list: &[String], exclusion_patterns: &[Regex]) -> bool {
|
||||||
|
|
Loading…
Reference in a new issue