diff options
author | Rory Dudley | 2024-03-26 13:33:05 -0600 |
---|---|---|
committer | Rory Dudley | 2024-03-26 13:33:05 -0600 |
commit | 279919230d1687c090ac1604779e28dc29e6588e (patch) | |
tree | 0f2f332dd547371001e2e2be260753b71996f5b4 | |
parent | 8e4cb90688998cca683fb3bfa885c6834079b3e9 (diff) | |
download | dwarvish-279919230d1687c090ac1604779e28dc29e6588e.tar.gz |
Don't error on dir read errors
Previously, if a directory could not be read, dwvsh would panic.
Instead of panicking, dwvsh should continue processing the other
directories on the $PATH.
-rw-r--r-- | src/path.rs | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/src/path.rs b/src/path.rs index 412489b..2953982 100644 --- a/src/path.rs +++ b/src/path.rs @@ -7,7 +7,7 @@ use std::path::Path; /// specified. /// /// # Arguments -/// * `paths` - A reference to a vector that holds a list to the shell $PATHs +/// * `path` - A reference to a vector that holds a list to the shell $PATHs /// /// # Returns /// * `bins: Vec<String>` - A new cache of all valid file paths in $PATH @@ -16,25 +16,19 @@ use std::path::Path; /// ``` /// let path = vec!["/bin"]; /// let path = path.into_iter().map(Path::new).collect(); -/// let mut bins = prefresh(&path); /// let mut bins = path::refresh(&path); /// ... /// // A situation occurs where the $PATH needs to be refreshed -/// bins = prefresh(&path) /// bins = path::refresh(&path) /// ``` -pub fn prefresh(path: &Vec<&Path>) -> Vec<String> { pub fn refresh(path: &Vec<&Path>) -> Vec<String> { let mut bins: Vec<String> = Vec::new(); for p in path { - let files = fs::read_dir(p).expect( - format!( - "dwvsh: error: unable to read the contents of {}", - p.display().to_string() - ) - .as_str(), - ); + let files = match fs::read_dir(p) { + Ok(files) => files, + Err(_) => continue, + }; for file in files { bins.push(file.unwrap().path().display().to_string()); |