diff options
Diffstat (limited to 'src/path.rs')
-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()); |