From 98a09fea2ee86351df66e448d9e6f05927cf706e Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Thu, 8 Mar 2018 20:05:27 +0100 Subject: [PATCH] Bugfix --- CHANGELOG.md | 1 + src/cli/args.rs | 2 +- src/cli/mod.rs | 10 +++++----- src/index.rs | 16 ++++------------ src/repository/backup.rs | 6 +++--- src/repository/integrity.rs | 7 ++++--- src/util/statistics.rs | 2 +- 7 files changed, 19 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d8886d..20d7a1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ This project follows [semantic versioning](http://semver.org). * [fixed] Also including the first min_size bytes in hash * [fixed] Fixed some texts in manpages * [fixed] Calling strip on final binaries +* [fixed] Fixed bug that caused repairs to miss some errors ### v0.4.0 (2017-07-21) diff --git a/src/cli/args.rs b/src/cli/args.rs index 98567f1..cb7a42a 100644 --- a/src/cli/args.rs +++ b/src/cli/args.rs @@ -214,7 +214,7 @@ fn validate_repo_path( fn parse_filesize(num: &str) -> Result { - let (num, suffix) = if num.len() > 0 { + let (num, suffix) = if !num.is_empty() { num.split_at(num.len() - 1) } else { (num, "b") diff --git a/src/cli/mod.rs b/src/cli/mod.rs index f3198fb..5c34f8f 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -138,7 +138,7 @@ fn get_backup(repo: &Repository, backup_name: &str) -> Result fn get_inode(repo: &mut Repository, backup: &Backup, inode: Option<&String>) -> Result { Ok(if let Some(inode) = inode { checked!( - repo.get_backup_inode(&backup, &inode), + repo.get_backup_inode(backup, &inode), "load subpath inode", ErrorCode::LoadInode ) @@ -340,7 +340,7 @@ fn print_repostats(stats: &RepositoryStatistics) { let disp = &stats.index.displacement; tr_println!("Displacement:\n - average: {:.1}\n - stddev: {:.1}\n - over {:.1}: {:.0}, {:.1}%\n - maximum: {:.0}", disp.avg, disp.stddev, disp.avg + 2.0 * disp.stddev, disp.count_xl, disp.count_xl as f32 / disp.count as f32 * 100.0, disp.max); - println!(""); + println!(); tr_println!("Bundles\n======="); let tsize = (stats.bundles.raw_size.count as f32 * stats.bundles.encoded_size.avg) as u64; tr_println!("All bundles: {} in {} bundles", to_file_size(tsize), stats.bundles.raw_size.count); @@ -366,7 +366,7 @@ fn print_repostats(stats: &RepositoryStatistics) { tr_println!(" - encoded size: ø = {}, maximum: {}", to_file_size(esize.avg as u64), to_file_size(esize.max as u64)); let ccount = &stats.bundles.chunk_count_data; tr_println!(" - chunk count: ø = {:.1}, maximum: {:.0}", ccount.avg, ccount.max); - println!(""); + println!(); tr_println!("Bundle methods\n=============="); tr_println!("Hash:"); for (hash, &count) in &stats.bundles.hash_methods { @@ -374,7 +374,7 @@ fn print_repostats(stats: &RepositoryStatistics) { } tr_println!("Compression:"); for (compr, &count) in &stats.bundles.compressions { - let compr_name = if let &Some(ref compr) = compr { + let compr_name = if let Some(ref compr) = *compr { compr.to_string() } else { tr!("none").to_string() @@ -383,7 +383,7 @@ fn print_repostats(stats: &RepositoryStatistics) { } tr_println!("Encryption:"); for (encr, &count) in &stats.bundles.encryptions { - let encr_name = if let &Some(ref encr) = encr { + let encr_name = if let Some(ref encr) = *encr { to_hex(&encr.1[..]) } else { tr!("none").to_string() diff --git a/src/index.rs b/src/index.rs index 86fff1c..f1da7af 100644 --- a/src/index.rs +++ b/src/index.rs @@ -59,14 +59,14 @@ pub struct Header { } -pub trait Key: Clone + Eq + Copy + Default { +pub trait Key: Eq + Copy + Default { fn hash(&self) -> u64; fn is_used(&self) -> bool; fn clear(&mut self); } -pub trait Value: Clone + Copy + Default {} +pub trait Value: Copy + Default {} #[repr(packed)] @@ -118,14 +118,6 @@ impl Entry { } } -impl Clone for Entry { - fn clone(&self) -> Self { - Entry { - key: *self.get_key(), - data: self.get_data().clone() - } - } -} #[derive(Debug)] pub enum LocateResult { @@ -416,12 +408,12 @@ impl Index { // we found a hole, stop shifting here break; } - if entry.get_key().hash() as usize & self.mask == pos { + if (entry.get_key().hash() as usize & self.mask) == pos { // we found an entry at the right position, stop shifting here break; } } - self.data[last_pos] = self.data[pos].clone(); + self.data.swap(last_pos, pos); } self.data[last_pos].clear(); } diff --git a/src/repository/backup.rs b/src/repository/backup.rs index 7fefdde..49d5b94 100644 --- a/src/repository/backup.rs +++ b/src/repository/backup.rs @@ -549,7 +549,7 @@ impl Repository { } if let Some(ref children) = inode.children { for chunks in children.values() { - let ch = try!(self.get_inode(&chunks)); + let ch = try!(self.get_inode(chunks)); try!(self.count_sizes_recursive(&ch, sizes, min_size)); } } @@ -567,7 +567,7 @@ impl Repository { } if let Some(ref children) = inode.children { for chunks in children.values() { - let ch = try!(self.get_inode(&chunks)); + let ch = try!(self.get_inode(chunks)); try!(self.find_duplicates_recursive(&ch, &path, sizes, hashes)); } } @@ -580,7 +580,7 @@ impl Repository { let mut hashes = HashMap::new(); if let Some(ref children) = inode.children { for chunks in children.values() { - let ch = try!(self.get_inode(&chunks)); + let ch = try!(self.get_inode(chunks)); try!(self.find_duplicates_recursive(&ch, Path::new(""), &sizes, &mut hashes)); } } diff --git a/src/repository/integrity.rs b/src/repository/integrity.rs index f95c303..c0bb31c 100644 --- a/src/repository/integrity.rs +++ b/src/repository/integrity.rs @@ -108,10 +108,11 @@ impl Repository { try!(self.check_chunks(checked, chunks, true)); } Some(FileData::ChunkedIndirect(ref chunks)) => { - if try!(self.check_chunks(checked, chunks, true)) { + if try!(self.check_chunks(checked, chunks, false)) { let chunk_data = try!(self.get_data(chunks)); - let chunks = ChunkList::read_from(&chunk_data); - try!(self.check_chunks(checked, &chunks, true)); + let chunks2 = ChunkList::read_from(&chunk_data); + try!(self.check_chunks(checked, &chunks2, true)); + try!(self.check_chunks(checked, chunks, true)); } } } diff --git a/src/util/statistics.rs b/src/util/statistics.rs index 934e863..71b40df 100644 --- a/src/util/statistics.rs +++ b/src/util/statistics.rs @@ -26,7 +26,7 @@ impl ValueStats { if stats.max < val { stats.max = val; } - sum += val as f64; + sum += f64::from(val); stats.count += 1; } stats.avg = (sum as f32) / (stats.count as f32);