Skip to content

Commit

Permalink
Skip directories with insufficient permissions instead of exiting (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
fpiribauer authored Oct 4, 2024
1 parent 01c2846 commit 5046106
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/repos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,24 @@ pub fn find_repos(config: &Config) -> Result<HashMap<String, Vec<Session>>> {
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))
}
}
}
}
}
Expand Down

0 comments on commit 5046106

Please sign in to comment.