summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Moroney <darakian@gmail.com>2020-08-02 14:30:34 -0700
committerJon Moroney <darakian@gmail.com>2020-08-02 14:30:38 -0700
commit806821e6cc9292f817821899253f61d04d61f3f4 (patch)
tree89a6dd50232f76e2798034b207527d5d088ac0b8
parent4e7c67c9260e6bd43f8d8ce4619a983017ca3366 (diff)
Skip unrapping hashes in comparison
Rust will inspect the contents of an option in equality checking Skipping the unwrap step resolves thread panics where a zero length file will have no hash
-rw-r--r--src/lib.rs6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 6a52695..0151143 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -331,9 +331,9 @@ fn differentiate_and_consolidate(file_length: u64, mut files: Vec<Fileinfo>) ->
});
return dedupe(files)
}
- let mut partial_hashes: HashMap<u128, u64> = HashMap::new();
+ let mut partial_hashes: HashMap<Option<u128>, u64> = HashMap::new();
for file in files.iter(){
- match partial_hashes.entry(file.get_partial_hash().unwrap()){
+ match partial_hashes.entry(file.get_partial_hash()){
Entry::Vacant(e) => { e.insert(0); },
Entry::Occupied(mut e) => {*e.get_mut()+=1;}
}
@@ -344,7 +344,7 @@ fn differentiate_and_consolidate(file_length: u64, mut files: Vec<Fileinfo>) ->
.map(|y| y.0)
.collect();
files.par_iter_mut().for_each(|x|
- if dedupe_hashes.contains(&x.get_partial_hash().unwrap()){
+ if dedupe_hashes.contains(&x.get_partial_hash()){
let hash = x.generate_hash(HashMode::Full);
x.set_full_hash(hash);
}