diff options
author | Isaac Parker <parrotmac@gmail.com> | 2019-11-17 19:20:58 -0800 |
---|---|---|
committer | nachoparker <nacho@ownyourbits.com> | 2019-11-18 03:20:58 +0000 |
commit | 203df3473fe01fafea9b3e4ccdb28a286b047dfe (patch) | |
tree | 0c3a7c7cb150389ffd1e0a2cf2462f15daa1e6a4 | |
parent | 72344f2780a37c947495ceb400a3ab59d4da8117 (diff) |
Gracefully handle bad or invalid symlinks (#29)v0.2.14
-rw-r--r-- | src/lib.rs | 16 |
1 files changed, 9 insertions, 7 deletions
@@ -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() { |