Bläddra i källkod

fix: crash using --git-repos on unreadable dir

This patch fixes the crash when the --git-repos flag is used on an
directory that doesn't have read permissions.

Fixes: #767
Erwin van Eijk 2 år sedan
förälder
incheckning
5a2fc5d360
1 ändrade filer med 8 tillägg och 4 borttagningar
  1. 8 4
      src/main.rs

+ 8 - 4
src/main.rs

@@ -199,10 +199,14 @@ fn git_repos(_options: &Options, _args: &[&OsStr]) -> bool {
 #[cfg(feature = "git")]
 fn get_files_in_dir(paths: &mut Vec<PathBuf>, path: PathBuf) {
     let temp_paths = if path.is_dir() {
-        path.read_dir()
-            .unwrap()
-            .map(|entry| entry.unwrap().path())
-            .collect::<Vec<PathBuf>>()
+        match path.read_dir() {
+            Err(_) => {
+                vec![path]
+            }
+            Ok(d) => d
+                .map(|entry| entry.unwrap().path())
+                .collect::<Vec<PathBuf>>(),
+        }
     } else {
         vec![path]
     };