diff --git a/src/main.rs b/src/main.rs index 3c9c3e1..944746e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ struct FileEntry { } fn collect_files(dir: &String, h: &mut HashMap>) { + let entries = match fs::read_dir(dir) { Ok(x) => x, _ => { @@ -25,25 +26,24 @@ fn collect_files(dir: &String, h: &mut HashMap>) { for path in entries.filter( |x| x.is_ok() ).map( |x| x.unwrap().path() ) .collect::>() { - if let Some(path_str) = path.to_str() { - if let Ok(metadata) = path.symlink_metadata() { - let ft = metadata.file_type(); - if ft.is_symlink() { - continue; - } else if ft.is_file() { - match metadata.len() { - 0 => continue, - i => h.entry(i).or_insert_with(Vec::new) - .push( - FileEntry{ - inode : metadata.ino(), - dev : metadata.dev(), - path : String::from(path_str), - }), - }; - } else if ft.is_dir() { - collect_files(&(String::from(path_str)), h); - } + if let (Some(path_str), Ok(metadata)) = + (path.to_str(), path.symlink_metadata()) { + let ft = metadata.file_type(); + if ft.is_symlink() { + continue; + } else if ft.is_file() { + match metadata.len() { + 0 => continue, + i => h.entry(i).or_insert_with(Vec::new) + .push( + FileEntry{ + inode : metadata.ino(), + dev : metadata.dev(), + path : String::from(path_str), + }), + }; + } else if ft.is_dir() { + collect_files(&(String::from(path_str)), h); } } }