From 2b811359f4b736ccf69653012b95199afb8cc2d7 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 6 Dec 2024 09:57:29 +0100 Subject: [PATCH] don't crash on weird directories --- src/utils/routes/cours.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/utils/routes/cours.rs b/src/utils/routes/cours.rs index 247ef6e..d5b62f8 100644 --- a/src/utils/routes/cours.rs +++ b/src/utils/routes/cours.rs @@ -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 = std::fs::read_dir(dir_path) - .unwrap() +) -> Result { + let mut children: Vec = 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() { - None + if let Ok(coc) = children_of_children { + if coc.is_dir && coc.children.is_empty() { + None + } else { + Some(coc) + } } else { - Some(children_of_children) + 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 {