From 618a8585069b01864ea2e7a4e2deb71086d62912 Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Mon, 19 Feb 2018 22:30:59 +0100 Subject: [PATCH] Make clippy happy --- chunking/Cargo.lock | 2 +- chunking/src/ae.rs | 2 +- chunking/src/fastcdc.rs | 4 ++-- chunking/src/fixed.rs | 2 +- chunking/src/rabin.rs | 2 +- index/Cargo.lock | 2 +- src/bundledb/db.rs | 14 ++++++++------ src/bundledb/reader.rs | 1 + src/chunker.rs | 2 +- src/cli/args.rs | 1 + src/cli/mod.rs | 12 ++++++------ src/mount.rs | 9 +++++---- src/repository/backup.rs | 12 +++++++----- src/repository/basic_io.rs | 2 +- src/repository/config.rs | 22 +++++++++++----------- src/repository/info.rs | 3 ++- src/repository/integrity.rs | 2 +- src/repository/mod.rs | 26 ++++++++++++++------------ src/repository/tarfile.rs | 9 +++++---- src/repository/vacuum.rs | 8 +++++--- src/util/encryption.rs | 3 ++- src/util/hash.rs | 1 - src/util/lock.rs | 3 ++- 23 files changed, 79 insertions(+), 65 deletions(-) diff --git a/chunking/Cargo.lock b/chunking/Cargo.lock index 2457033..13d70a8 100644 --- a/chunking/Cargo.lock +++ b/chunking/Cargo.lock @@ -1,4 +1,4 @@ -[root] +[[package]] name = "chunking" version = "0.1.0" dependencies = [ diff --git a/chunking/src/ae.rs b/chunking/src/ae.rs index e562561..8358db4 100644 --- a/chunking/src/ae.rs +++ b/chunking/src/ae.rs @@ -27,7 +27,7 @@ impl AeChunker { impl Chunker for AeChunker { #[allow(unknown_lints,explicit_counter_loop)] - fn chunk(&mut self, r: &mut Read, mut w: &mut Write) -> Result { + fn chunk(&mut self, r: &mut Read, w: &mut Write) -> Result { let mut max; let mut pos = 0; let mut max_pos = 0; diff --git a/chunking/src/fastcdc.rs b/chunking/src/fastcdc.rs index a02e5ab..106c858 100644 --- a/chunking/src/fastcdc.rs +++ b/chunking/src/fastcdc.rs @@ -88,7 +88,7 @@ impl FastCdcChunker { impl Chunker for FastCdcChunker { #[allow(unknown_lints,explicit_counter_loop,needless_range_loop)] - fn chunk(&mut self, r: &mut Read, mut w: &mut Write) -> Result { + fn chunk(&mut self, r: &mut Read, w: &mut Write) -> Result { let mut max; let mut hash = 0u64; let mut pos = 0; @@ -107,7 +107,7 @@ impl Chunker for FastCdcChunker { for i in min_size_p..avg_size_p { hash = (hash << 1).wrapping_add(self.gear[self.buffer[i] as usize]); if hash & self.mask_short == 0 { - return self.write_output(w, i+1, max); + return self.write_output(w, i + 1, max); } } } diff --git a/chunking/src/fixed.rs b/chunking/src/fixed.rs index e738297..621aeee 100644 --- a/chunking/src/fixed.rs +++ b/chunking/src/fixed.rs @@ -19,7 +19,7 @@ impl FixedChunker { impl Chunker for FixedChunker { #[allow(unknown_lints,explicit_counter_loop)] - fn chunk(&mut self, r: &mut Read, mut w: &mut Write) -> Result { + fn chunk(&mut self, r: &mut Read, w: &mut Write) -> Result { let mut todo = self.size; loop { // Fill the buffer, there might be some bytes still in there from last chunk diff --git a/chunking/src/rabin.rs b/chunking/src/rabin.rs index 36e54a0..70487a4 100644 --- a/chunking/src/rabin.rs +++ b/chunking/src/rabin.rs @@ -67,7 +67,7 @@ impl RabinChunker { impl Chunker for RabinChunker { #[allow(unknown_lints,explicit_counter_loop)] - fn chunk(&mut self, r: &mut Read, mut w: &mut Write) -> Result { + fn chunk(&mut self, r: &mut Read, w: &mut Write) -> Result { let mut max; let mut hash = 0u32; let mut pos = 0; diff --git a/index/Cargo.lock b/index/Cargo.lock index 4220f63..fb7ce5b 100644 --- a/index/Cargo.lock +++ b/index/Cargo.lock @@ -1,4 +1,4 @@ -[root] +[[package]] name = "index" version = "0.1.0" dependencies = [ diff --git a/src/bundledb/db.rs b/src/bundledb/db.rs index ab67fde..d1c6108 100644 --- a/src/bundledb/db.rs +++ b/src/bundledb/db.rs @@ -57,6 +57,7 @@ quick_error!{ } +#[allow(needless_pass_by_value)] fn load_bundles( path: &Path, base: &Path, @@ -195,10 +196,11 @@ impl BundleDb { &self.layout.local_bundle_cache_path() )); let bundles: Vec<_> = self.remote_bundles.values().cloned().collect(); - Ok(try!(StoredBundle::save_list_to( + try!(StoredBundle::save_list_to( &bundles, &self.layout.remote_bundle_cache_path() - ))) + )); + Ok(()) } fn update_cache(&mut self) -> Result<(), BundleDbError> { @@ -244,7 +246,7 @@ impl BundleDb { Ok((self_, new, gone)) } - pub fn create(layout: RepositoryLayout) -> Result<(), BundleDbError> { + pub fn create(layout: &RepositoryLayout) -> Result<(), BundleDbError> { try!(fs::create_dir_all(layout.remote_bundles_path()).context( &layout.remote_bundles_path() as &Path @@ -432,7 +434,7 @@ impl BundleDb { } if !to_repair.is_empty() { for id in ProgressIter::new("repairing bundles", to_repair.len(), to_repair.iter()) { - try!(self.repair_bundle(id.clone())); + try!(self.repair_bundle(id)); } try!(self.flush()); } @@ -453,8 +455,8 @@ impl BundleDb { Ok(()) } - fn repair_bundle(&mut self, id: BundleId) -> Result<(), BundleDbError> { - let stored = self.remote_bundles[&id].clone(); + fn repair_bundle(&mut self, id: &BundleId) -> Result<(), BundleDbError> { + let stored = self.remote_bundles[id].clone(); let mut bundle = match self.get_bundle(&stored) { Ok(bundle) => bundle, Err(err) => { diff --git a/src/bundledb/reader.rs b/src/bundledb/reader.rs index 0b9aac6..72c8a1d 100644 --- a/src/bundledb/reader.rs +++ b/src/bundledb/reader.rs @@ -90,6 +90,7 @@ impl BundleReader { self.info.id.clone() } + #[allow(needless_pass_by_value)] fn load_header>( path: P, crypto: Arc>, diff --git a/src/chunker.rs b/src/chunker.rs index 337c311..f23af52 100644 --- a/src/chunker.rs +++ b/src/chunker.rs @@ -79,7 +79,7 @@ impl ChunkerType { match *self { ChunkerType::Ae(_size) | ChunkerType::Fixed(_size) => 0, - ChunkerType::Rabin((_size, seed)) => seed as u64, + ChunkerType::Rabin((_size, seed)) => u64::from(seed), ChunkerType::FastCdc((_size, seed)) => seed, } } diff --git a/src/cli/args.rs b/src/cli/args.rs index fa74515..e1907a4 100644 --- a/src/cli/args.rs +++ b/src/cli/args.rs @@ -5,6 +5,7 @@ use std::path::{Path, PathBuf}; use log::LogLevel; use clap::{App, AppSettings, Arg, SubCommand}; +#[allow(option_option)] pub enum Arguments { Init { repo_path: PathBuf, diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 314ad28..1f185f9 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -89,11 +89,11 @@ impl ErrorCode { } -pub const DEFAULT_CHUNKER: &'static str = "fastcdc/16"; -pub const DEFAULT_HASH: &'static str = "blake2"; -pub const DEFAULT_COMPRESSION: &'static str = "brotli/3"; -pub const DEFAULT_BUNDLE_SIZE_STR: &'static str = "25"; -pub const DEFAULT_VACUUM_RATIO_STR: &'static str = "0"; +pub const DEFAULT_CHUNKER: &str = "fastcdc/16"; +pub const DEFAULT_HASH: &str = "blake2"; +pub const DEFAULT_COMPRESSION: &str = "brotli/3"; +pub const DEFAULT_BUNDLE_SIZE_STR: &str = "25"; +pub const DEFAULT_VACUUM_RATIO_STR: &str = "0"; lazy_static! { pub static ref ZVAULT_FOLDER: PathBuf = { env::home_dir().unwrap().join(".zvault") @@ -435,7 +435,7 @@ pub fn run() -> Result<(), ErrorCode> { let mut repo = checked!( Repository::create( repo_path, - Config { + &Config { bundle_size: bundle_size, chunker: chunker, compression: compression, diff --git a/src/mount.rs b/src/mount.rs index 4435c1b..a2f049b 100644 --- a/src/mount.rs +++ b/src/mount.rs @@ -260,7 +260,7 @@ impl<'a> FuseFilesystem<'a> { } pub fn mount>(self, mountpoint: P) -> Result<(), RepositoryError> { - Ok(try!(fuse::mount( + try!(fuse::mount( self, &mountpoint, &[ @@ -269,7 +269,8 @@ impl<'a> FuseFilesystem<'a> { OsStr::new("auto_cache"), OsStr::new("readonly"), ] - ))) + )); + Ok(()) } pub fn get_inode(&mut self, num: u64) -> Option { @@ -551,8 +552,8 @@ impl<'a> fuse::Filesystem for FuseFilesystem<'a> { if let Some(ref chunks) = inode.chunks { let mut data = Vec::with_capacity(size as usize); for &(hash, len) in chunks.iter() { - if len as u64 <= offset { - offset -= len as u64; + if u64::from(len) <= offset { + offset -= u64::from(len); continue; } let chunk = match fuse_try!(self.repository.get_chunk(hash), reply) { diff --git a/src/repository/backup.rs b/src/repository/backup.rs index 4715f87..e7345f4 100644 --- a/src/repository/backup.rs +++ b/src/repository/backup.rs @@ -73,11 +73,12 @@ impl Repository { try!(self.write_mode()); let path = self.layout.backup_path(name); try!(fs::create_dir_all(path.parent().unwrap())); - Ok(try!(backup.save_to( + try!(backup.save_to( &self.crypto.lock().unwrap(), self.config.encryption.clone(), path - ))) + )); + Ok(()) } pub fn delete_backup(&mut self, name: &str) -> Result<(), RepositoryError> { @@ -298,7 +299,7 @@ impl Repository { let chunks = try!(self.put_inode(&child_inode)); inode.cum_size += child_inode.cum_size; for &(_, len) in chunks.iter() { - meta_size += len as u64; + meta_size += u64::from(len); } inode.cum_dirs += child_inode.cum_dirs; inode.cum_files += child_inode.cum_files; @@ -309,7 +310,7 @@ impl Repository { inode.cum_files = 1; if let Some(FileData::ChunkedIndirect(ref chunks)) = inode.data { for &(_, len) in chunks.iter() { - meta_size += len as u64; + meta_size += u64::from(len); } } } @@ -357,7 +358,7 @@ impl Repository { backup.timestamp = start.timestamp(); backup.total_data_size = root_inode.cum_size; for &(_, len) in backup.root.iter() { - backup.total_data_size += len as u64; + backup.total_data_size += u64::from(len); } backup.file_count = root_inode.cum_files; backup.dir_count = root_inode.cum_dirs; @@ -474,6 +475,7 @@ impl Repository { Ok(versions) } + #[allow(needless_pass_by_value)] fn find_differences_recurse( &mut self, inode1: &Inode, diff --git a/src/repository/basic_io.rs b/src/repository/basic_io.rs index 16e112f..0609d75 100644 --- a/src/repository/basic_io.rs +++ b/src/repository/basic_io.rs @@ -25,7 +25,7 @@ impl<'a> ChunkReader<'a> { } impl<'a> Read for ChunkReader<'a> { - fn read(&mut self, mut buf: &mut [u8]) -> Result { + fn read(&mut self, buf: &mut [u8]) -> Result { let mut bpos = 0; loop { if buf.len() == bpos { diff --git a/src/repository/config.rs b/src/repository/config.rs index c31e246..8217b40 100644 --- a/src/repository/config.rs +++ b/src/repository/config.rs @@ -30,8 +30,8 @@ quick_error!{ impl HashMethod { - fn from_yaml(yaml: String) -> Result { - HashMethod::from(&yaml).map_err(ConfigError::Parse) + fn from_yaml(yaml: &str) -> Result { + HashMethod::from(yaml).map_err(ConfigError::Parse) } fn to_yaml(&self) -> String { @@ -61,7 +61,7 @@ serde_impl!(ChunkerYaml(String) { }); impl ChunkerType { - fn from_yaml(yaml: ChunkerYaml) -> Result { + fn from_yaml(yaml: &ChunkerYaml) -> Result { ChunkerType::from(&yaml.method, yaml.avg_size, yaml.seed).map_err(ConfigError::Parse) } @@ -78,8 +78,8 @@ impl ChunkerType { impl Compression { #[inline] - fn from_yaml(yaml: String) -> Result { - Compression::from_string(&yaml).map_err(|_| ConfigError::Parse("Invalid codec")) + fn from_yaml(yaml: &str) -> Result { + Compression::from_string(yaml).map_err(|_| ConfigError::Parse("Invalid codec")) } #[inline] @@ -91,8 +91,8 @@ impl Compression { impl EncryptionMethod { #[inline] - fn from_yaml(yaml: String) -> Result { - EncryptionMethod::from_string(&yaml).map_err(|_| ConfigError::Parse("Invalid codec")) + fn from_yaml(yaml: &str) -> Result { + EncryptionMethod::from_string(yaml).map_err(|_| ConfigError::Parse("Invalid codec")) } #[inline] @@ -179,12 +179,12 @@ serde_impl!(Config(u64) { impl Config { fn from_yaml(yaml: ConfigYaml) -> Result { let compression = if let Some(c) = yaml.compression { - Some(try!(Compression::from_yaml(c))) + Some(try!(Compression::from_yaml(&c))) } else { None }; let encryption = if let Some(e) = yaml.encryption { - let method = try!(EncryptionMethod::from_yaml(e.method)); + let method = try!(EncryptionMethod::from_yaml(&e.method)); let key = try!(parse_hex(&e.key).map_err(|_| { ConfigError::Parse("Invalid public key") })); @@ -196,8 +196,8 @@ impl Config { compression: compression, encryption: encryption, bundle_size: yaml.bundle_size, - chunker: try!(ChunkerType::from_yaml(yaml.chunker)), - hash: try!(HashMethod::from_yaml(yaml.hash)) + chunker: try!(ChunkerType::from_yaml(&yaml.chunker)), + hash: try!(HashMethod::from_yaml(&yaml.hash)) }) } diff --git a/src/repository/info.rs b/src/repository/info.rs index 42321ae..9840b45 100644 --- a/src/repository/info.rs +++ b/src/repository/info.rs @@ -48,7 +48,8 @@ impl Repository { let mut new = false; for &(hash, len) in chunks { if let Some(pos) = self.index.get(&hash) { - if let Some(bundle) = bundles.get_mut(&pos.bundle) { + let bundle = pos.bundle; + if let Some(bundle) = bundles.get_mut(&bundle) { if !bundle.chunk_usage.get(pos.chunk as usize) { new = true; bundle.chunk_usage.set(pos.chunk as usize); diff --git a/src/repository/integrity.rs b/src/repository/integrity.rs index 7338af3..1bc957c 100644 --- a/src/repository/integrity.rs +++ b/src/repository/integrity.rs @@ -488,7 +488,7 @@ impl Repository { ); return self.rebuild_index(); } else { - return Err(err.into()); + return Err(err); } } Ok(()) diff --git a/src/repository/mod.rs b/src/repository/mod.rs index 0ea3885..95fcd57 100644 --- a/src/repository/mod.rs +++ b/src/repository/mod.rs @@ -32,8 +32,8 @@ pub use self::layout::RepositoryLayout; use self::bundle_map::BundleMap; -const REPOSITORY_README: &'static [u8] = include_bytes!("../../docs/repository_readme.md"); -const DEFAULT_EXCLUDES: &'static [u8] = include_bytes!("../../docs/excludes.default"); +const REPOSITORY_README: &[u8] = include_bytes!("../../docs/repository_readme.md"); +const DEFAULT_EXCLUDES: &[u8] = include_bytes!("../../docs/excludes.default"); const INDEX_MAGIC: [u8; 7] = *b"zvault\x02"; const INDEX_VERSION: u8 = 1; @@ -93,7 +93,7 @@ pub struct Repository { impl Repository { pub fn create, R: AsRef>( path: P, - config: Config, + config: &Config, remote: R, ) -> Result { let layout = RepositoryLayout::new(path.as_ref().to_path_buf()); @@ -111,7 +111,7 @@ impl Repository { )); try!(fs::create_dir_all(layout.remote_locks_path())); try!(config.save(layout.config_path())); - try!(BundleDb::create(layout.clone())); + try!(BundleDb::create(&layout)); try!(Index::::create( layout.index_path(), &INDEX_MAGIC, @@ -181,7 +181,7 @@ impl Repository { info!("Removig {} old bundles from index", gone.len()); try!(repo.write_mode()); for bundle in gone { - try!(repo.remove_gone_remote_bundle(bundle)) + try!(repo.remove_gone_remote_bundle(&bundle)) } save_bundle_map = true; } @@ -194,7 +194,7 @@ impl Repository { new.into_iter() ) { - try!(repo.add_new_remote_bundle(bundle)) + try!(repo.add_new_remote_bundle(&bundle)) } save_bundle_map = true; } @@ -224,7 +224,7 @@ impl Repository { key_files: Vec, ) -> Result { let path = path.as_ref(); - let mut repo = try!(Repository::create(path, Config::default(), remote)); + let mut repo = try!(Repository::create(path, &Config::default(), remote)); for file in key_files { try!(repo.crypto.lock().unwrap().register_keyfile(file)); } @@ -250,10 +250,11 @@ impl Repository { secret: SecretKey, ) -> Result<(), RepositoryError> { try!(self.write_mode()); - Ok(try!(self.crypto.lock().unwrap().register_secret_key( + try!(self.crypto.lock().unwrap().register_secret_key( public, secret - ))) + )); + Ok(()) } #[inline] @@ -338,7 +339,7 @@ impl Repository { Ok(()) } - fn add_new_remote_bundle(&mut self, bundle: BundleInfo) -> Result<(), RepositoryError> { + fn add_new_remote_bundle(&mut self, bundle: &BundleInfo) -> Result<(), RepositoryError> { if self.bundle_map.find(&bundle.id).is_some() { return Ok(()); } @@ -374,7 +375,7 @@ impl Repository { Ok(()) } - fn remove_gone_remote_bundle(&mut self, bundle: BundleInfo) -> Result<(), RepositoryError> { + fn remove_gone_remote_bundle(&mut self, bundle: &BundleInfo) -> Result<(), RepositoryError> { if let Some(id) = self.bundle_map.find(&bundle.id) { debug!("Removing bundle from index: {}", bundle.id); try!(self.bundles.delete_local_bundle(&bundle.id)); @@ -386,7 +387,8 @@ impl Repository { #[inline] fn write_mode(&mut self) -> Result<(), RepositoryError> { - Ok(try!(self.local_locks.upgrade(&mut self.lock))) + try!(self.local_locks.upgrade(&mut self.lock)); + Ok(()) } #[inline] diff --git a/src/repository/tarfile.rs b/src/repository/tarfile.rs index f474788..a9538a9 100644 --- a/src/repository/tarfile.rs +++ b/src/repository/tarfile.rs @@ -177,7 +177,7 @@ impl Repository { } else { if let Some(FileData::ChunkedIndirect(ref chunks)) = inode.data { for &(_, len) in chunks.iter() { - inode.cum_size += len as u64; + inode.cum_size += u64::from(len); } } inode.cum_files = 1; @@ -226,7 +226,7 @@ impl Repository { children.remove(&inode.name); parent_inode.cum_size += inode.cum_size; for &(_, len) in chunks.iter() { - parent_inode.cum_size += len as u64; + parent_inode.cum_size += u64::from(len); } parent_inode.cum_files += inode.cum_files; parent_inode.cum_dirs += inode.cum_dirs; @@ -257,7 +257,7 @@ impl Repository { for (inode, chunks) in roots { root_inode.cum_size += inode.cum_size; for &(_, len) in chunks.iter() { - root_inode.cum_size += len as u64; + root_inode.cum_size += u64::from(len); } root_inode.cum_files += inode.cum_files; root_inode.cum_dirs += inode.cum_dirs; @@ -334,7 +334,8 @@ impl Repository { str::from_utf8(value).unwrap() ); } - Ok(try!(tarfile.append_pax_extensions(&pax))) + try!(tarfile.append_pax_extensions(&pax)); + Ok(()) } fn export_tarfile_recurse( diff --git a/src/repository/vacuum.rs b/src/repository/vacuum.rs index d008846..55daa6b 100644 --- a/src/repository/vacuum.rs +++ b/src/repository/vacuum.rs @@ -102,12 +102,14 @@ impl Repository { try!(self.flush()); info!("Checking index"); for (hash, location) in self.index.iter() { - if rewrite_bundles.contains(&location.bundle) { + let loc_bundle = location.bundle; + let loc_chunk = location.chunk; + if rewrite_bundles.contains(&loc_bundle) { panic!( "Removed bundle is still referenced in index: hash:{}, bundle:{}, chunk:{}", hash, - location.bundle, - location.chunk + loc_bundle, + loc_chunk ); } } diff --git a/src/util/encryption.rs b/src/util/encryption.rs index 17a23bb..41ee20b 100644 --- a/src/util/encryption.rs +++ b/src/util/encryption.rs @@ -108,7 +108,8 @@ impl KeyfileYaml { pub fn save>(&self, path: P) -> Result<(), EncryptionError> { let mut f = try!(File::create(path)); - Ok(try!(serde_yaml::to_writer(&mut f, &self))) + try!(serde_yaml::to_writer(&mut f, &self)); + Ok(()) } } diff --git a/src/util/hash.rs b/src/util/hash.rs index 364b475..e8d2e93 100644 --- a/src/util/hash.rs +++ b/src/util/hash.rs @@ -12,7 +12,6 @@ use std::u64; use std::io::{self, Read, Write}; -#[repr(packed)] #[derive(Clone, Copy, PartialEq, Hash, Eq, Default, Ord, PartialOrd)] pub struct Hash { pub high: u64, diff --git a/src/util/lock.rs b/src/util/lock.rs index f07ed97..35d367e 100644 --- a/src/util/lock.rs +++ b/src/util/lock.rs @@ -58,7 +58,8 @@ impl LockFile { pub fn save>(&self, path: P) -> Result<(), LockError> { let mut f = try!(File::create(path)); - Ok(try!(serde_yaml::to_writer(&mut f, &self))) + try!(serde_yaml::to_writer(&mut f, &self)); + Ok(()) } }