From 5046106ae0873b16099dae01c327c162e8debb37 Mon Sep 17 00:00:00 2001 From: Fabian Piribauer <31340681+fpiribauer@users.noreply.github.com> Date: Sat, 5 Oct 2024 01:24:48 +0200 Subject: [PATCH] Skip directories with insufficient permissions instead of exiting (#125) --- src/repos.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/repos.rs b/src/repos.rs index 421bc06..3f64302 100644 --- a/src/repos.rs +++ b/src/repos.rs @@ -54,12 +54,24 @@ pub fn find_repos(config: &Config) -> Result>> { repos.insert(session.name.clone(), vec![session]); } } else if file.path.is_dir() && file.depth > 0 { - let read_dir = fs::read_dir(&file.path) - .change_context(TmsError::IoError) - .attach_printable_lazy(|| format!("Could not read directory {:?}", file.path))? - .map(|dir_entry| dir_entry.expect("Found non-valid utf8 path").path()); - for dir in read_dir { - to_search.push_back(SearchDirectory::new(dir, file.depth - 1)) + match fs::read_dir(&file.path) { + Err(ref e) if e.kind() == std::io::ErrorKind::PermissionDenied => { + eprintln!( + "Warning: insufficient permissions to read '{0}'. Skipping directory...", + file.path.to_string()? + ); + } + result => { + let read_dir = result + .change_context(TmsError::IoError) + .attach_printable_lazy(|| { + format!("Could not read directory {:?}", file.path) + })? + .map(|dir_entry| dir_entry.expect("Found non-valid utf8 path").path()); + for dir in read_dir { + to_search.push_back(SearchDirectory::new(dir, file.depth - 1)) + } + } } } }