Skip to content

Commit

Permalink
Gracefully handle bad or invalid symlinks (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
parrotmac authored and nachoparker committed Nov 18, 2019
1 parent 72344f2 commit 203df34
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,15 +481,17 @@ fn get_bytes( path: &Path, usage_flag : bool ) -> u64 {

fn color_from_path<'a>( path : &Path, color_dict : &'a HashMap<String, String> ) -> Option<&'a str> {
if try_is_symlink( path ) {
if path.read_link().unwrap().exists() {
if let Some( col ) = color_dict.get( &"ln".to_string() ) {
return Some( &col );
}
} else {
if let Some( col ) = color_dict.get( &"or".to_string() ) {
return Some( &col );
let path_link = path.read_link();
if path_link.is_ok() {
if path_link.unwrap().exists() {
if let Some(col) = color_dict.get(&"ln".to_string()) {
return Some(&col);
}
}
}
if let Some( col ) = color_dict.get( &"or".to_string() ) {
return Some( &col );
}
}
let metadata = path.symlink_metadata();
if metadata.is_ok() {
Expand Down

0 comments on commit 203df34

Please sign in to comment.