Skip to content

Commit

Permalink
Remove usage of unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp committed Nov 1, 2018
1 parent 9dfb398 commit 903d8a1
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,37 @@ fn main() {
walker.run(|| {
let tx = tx.clone();
Box::new(move |result| {
if let Ok(entry) = result {
let metadata = entry.metadata().unwrap();
match result {
Ok(entry) => {
if let Ok(metadata) = entry.metadata() {
// If the entry has more than one hard link, generate
// a unique ID consisting of device and inode in order
// not to count this entry twice.
let unique_id = if metadata.is_file() && metadata.nlink() > 1 {
Some((metadata.dev(), metadata.ino()))
} else {
None
};

// If the entry has more than one hard link, generate
// a unique ID consisting of device and inode in order
// not to count this entry twice.
let unique_id = if metadata.is_file() && metadata.nlink() > 1 {
Some((metadata.dev(), metadata.ino()))
} else {
None
};
let size = metadata.len();

let size = metadata.len();

tx.send((unique_id, size)).unwrap();
tx.send((unique_id, size)).ok();
} else {
eprintln!(
"Could not get metadata: '{}'",
entry.path().to_string_lossy()
);
}
}
Err(err) => {
eprintln!("I/O error: {}", err);
}
}

return ignore::WalkState::Continue;
})
});

drop(tx);
receiver_thread.join().unwrap();
receiver_thread.join().ok();
}

0 comments on commit 903d8a1

Please sign in to comment.