1
0
Fork 0
mirror of https://github.com/nachoparker/dutree synced 2024-05-08 23:16:06 +02:00

Gracefully handle bad or invalid symlinks (#29)

This commit is contained in:
Isaac Parker 2019-11-17 19:20:58 -08:00 committed by nachoparker
parent 72344f2780
commit 203df3473f

View File

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