Skip to content

Commit

Permalink
Use tuples to unbox multiple values.
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshsundriyal committed Oct 5, 2017
1 parent e51a50f commit 1c8b318
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct FileEntry {
}

fn collect_files(dir: &String, h: &mut HashMap<u64, Vec<FileEntry>>) {

let entries = match fs::read_dir(dir) {
Ok(x) => x,
_ => {
Expand All @@ -25,25 +26,24 @@ fn collect_files(dir: &String, h: &mut HashMap<u64, Vec<FileEntry>>) {

for path in entries.filter( |x| x.is_ok() ).map( |x| x.unwrap().path() )
.collect::<Vec<PathBuf>>() {
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);
}
}
}
Expand Down

0 comments on commit 1c8b318

Please sign in to comment.