From 11026008938a31e287a80f2f7d13470efa9e48b2 Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Sat, 3 Mar 2018 17:25:05 +0100 Subject: [PATCH] Some changes --- CHANGELOG.md | 6 ++++++ src/bundledb/db.rs | 8 ++++---- src/bundledb/reader.rs | 10 +++++----- src/bundledb/uploader.rs | 2 +- src/bundledb/writer.rs | 18 +++++++++--------- src/chunking/ae.rs | 2 +- src/chunking/fastcdc.rs | 6 +++--- src/chunking/rabin.rs | 8 ++++---- src/cli/logger.rs | 18 +++++------------- src/cli/mod.rs | 26 +++++++++++++------------- src/index.rs | 10 +++++----- src/mount.rs | 10 +++++----- src/repository/backup_file.rs | 2 +- src/repository/basic_io.rs | 2 +- src/repository/config.rs | 4 ++-- src/repository/info.rs | 6 +++--- src/repository/mod.rs | 22 +++++++++++----------- src/repository/tarfile.rs | 2 +- src/translation.rs | 10 +++++----- src/util/bitmap.rs | 4 ++-- src/util/cli.rs | 6 +++--- src/util/compression.rs | 6 +++--- src/util/encryption.rs | 2 +- src/util/hash.rs | 8 ++++---- src/util/lock.rs | 4 ++-- src/util/lru_cache.rs | 4 ++-- 26 files changed, 102 insertions(+), 104 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 718fa05..1a630c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ This project follows [semantic versioning](http://semver.org). +### UNRELEASED +* [added] Translation infrastructure (**requires nightly rust**) +* [fixed] Also including the first min_size bytes in hash +* [modified] Updated dependencies + + ### v0.4.0 (2017-07-21) * [added] Added `copy` subcommand * [added] Added support for xattrs in fuse mount diff --git a/src/bundledb/db.rs b/src/bundledb/db.rs index e2df24e..c14a5fd 100644 --- a/src/bundledb/db.rs +++ b/src/bundledb/db.rs @@ -99,8 +99,8 @@ fn load_bundles( } }; let bundle = StoredBundle { - info: info, - path: path + info, + path }; let id = bundle.info.id.clone(); if !bundles.contains_key(&id) { @@ -129,8 +129,8 @@ pub struct BundleDb { impl BundleDb { fn new(layout: RepositoryLayout, crypto: Arc>) -> Self { BundleDb { - layout: layout, - crypto: crypto, + layout, + crypto, uploader: None, local_bundles: HashMap::new(), remote_bundles: HashMap::new(), diff --git a/src/bundledb/reader.rs b/src/bundledb/reader.rs index fd86e55..64e6d6b 100644 --- a/src/bundledb/reader.rs +++ b/src/bundledb/reader.rs @@ -75,12 +75,12 @@ impl BundleReader { info: BundleInfo, ) -> Self { BundleReader { - info: info, + info, chunks: None, - version: version, - path: path, - crypto: crypto, - content_start: content_start, + version, + path, + crypto, + content_start, chunk_positions: None } } diff --git a/src/bundledb/uploader.rs b/src/bundledb/uploader.rs index 1a96087..73ff4fb 100644 --- a/src/bundledb/uploader.rs +++ b/src/bundledb/uploader.rs @@ -20,7 +20,7 @@ pub struct BundleUploader { impl BundleUploader { pub fn new(capacity: usize) -> Arc { let self_ = Arc::new(BundleUploader { - capacity: capacity, + capacity, error_present: AtomicBool::new(false), error: Mutex::new(None), waiting: AtomicUsize::new(0), diff --git a/src/bundledb/writer.rs b/src/bundledb/writer.rs index f7aca9c..41cccaa 100644 --- a/src/bundledb/writer.rs +++ b/src/bundledb/writer.rs @@ -72,13 +72,13 @@ impl BundleWriter { None => None, }; Ok(BundleWriter { - mode: mode, - hash_method: hash_method, + mode, + hash_method, data: vec![], - compression: compression, - compression_stream: compression_stream, - encryption: encryption, - crypto: crypto, + compression, + compression_stream, + encryption, + crypto, raw_size: 0, chunk_count: 0, chunks: ChunkList::new() @@ -127,7 +127,7 @@ impl BundleWriter { chunk_count: self.chunk_count, id: id.clone(), raw_size: self.raw_size, - encoded_size: encoded_size, + encoded_size, chunk_list_size: chunk_data.len(), timestamp: Local::now().timestamp() }; @@ -149,8 +149,8 @@ impl BundleWriter { .unwrap() .to_path_buf(); Ok(StoredBundle { - path: path, - info: info + path, + info }) } diff --git a/src/chunking/ae.rs b/src/chunking/ae.rs index c551742..720fbc4 100644 --- a/src/chunking/ae.rs +++ b/src/chunking/ae.rs @@ -20,7 +20,7 @@ impl AeChunker { AeChunker{ buffer: [0; 0x1000], buffered: 0, - window_size: window_size, + window_size, } } } diff --git a/src/chunking/fastcdc.rs b/src/chunking/fastcdc.rs index 23b97ea..d6f61bf 100644 --- a/src/chunking/fastcdc.rs +++ b/src/chunking/fastcdc.rs @@ -66,9 +66,9 @@ impl FastCdcChunker { gear: create_gear(seed), min_size: avg_size/4, max_size: avg_size*8, - avg_size: avg_size, - mask_long: mask_long, - mask_short: mask_short, + avg_size, + mask_long, + mask_short, } } } diff --git a/src/chunking/rabin.rs b/src/chunking/rabin.rs index 486caa9..e843e54 100644 --- a/src/chunking/rabin.rs +++ b/src/chunking/rabin.rs @@ -55,12 +55,12 @@ impl RabinChunker { buffer: [0; 0x1000], buffered: 0, table: create_table(alpha, window_size), - alpha: alpha, - seed: seed, + alpha, + seed, min_size: avg_size/4, max_size: avg_size*4, - window_size: window_size, - chunk_mask: chunk_mask, + window_size, + chunk_mask, } } } diff --git a/src/cli/logger.rs b/src/cli/logger.rs index fba67c6..462cfe3 100644 --- a/src/cli/logger.rs +++ b/src/cli/logger.rs @@ -2,16 +2,8 @@ use log; pub use log::SetLoggerError; use ansi_term::{Color, Style}; -use std::io::Write; -macro_rules! println_stderr( - ($($arg:tt)*) => { { - let r = writeln!(&mut ::std::io::stderr(), $($arg)*); - r.expect("failed printing to stderr"); - } } -); - struct Logger(log::Level); impl log::Log for Logger { @@ -25,22 +17,22 @@ impl log::Log for Logger { if self.enabled(record.metadata()) { match record.level() { log::Level::Error => { - println_stderr!("{}: {}", Color::Red.bold().paint("error"), record.args()) + eprintln!("{}: {}", Color::Red.bold().paint("error"), record.args()) } log::Level::Warn => { - println_stderr!( + eprintln!( "{}: {}", Color::Yellow.bold().paint("warning"), record.args() ) } log::Level::Info => { - println_stderr!("{}: {}", Color::Green.bold().paint("info"), record.args()) + eprintln!("{}: {}", Color::Green.bold().paint("info"), record.args()) } log::Level::Debug => { - println_stderr!("{}: {}", Style::new().bold().paint("debug"), record.args()) + eprintln!("{}: {}", Style::new().bold().paint("debug"), record.args()) } - log::Level::Trace => println_stderr!("{}: {}", "trace", record.args()), + log::Level::Trace => eprintln!("{}: {}", "trace", record.args()), } } } diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 70b14a8..8072738 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -105,7 +105,7 @@ macro_rules! checked { match $expr { Ok(val) => val, Err(err) => { - tr_error!("Failed to {}\n\tcaused by: {}", $msg, err); + tr_error!("Failed to {}\n\tcaused by: {}", tr!($msg), err); return Err($code) } } @@ -187,16 +187,16 @@ fn print_backup(backup: &Backup) { ); let dedup_ratio = backup.deduplicated_data_size as f32 / backup.changed_data_size as f32; tr_println!( - "Deduplicated size: {}, {:.1}% saved", + "Deduplicated size: {}, {:.1}%", to_file_size(backup.deduplicated_data_size), - (1.0 - dedup_ratio) * 100.0 + (dedup_ratio - 1.0) * 100.0 ); let compress_ratio = backup.encoded_data_size as f32 / backup.deduplicated_data_size as f32; tr_println!( - "Compressed size: {} in {} bundles, {:.1}% saved", + "Compressed size: {} in {} bundles, {:.1}%", to_file_size(backup.encoded_data_size), backup.bundle_count, - (1.0 - compress_ratio) * 100.0 + (compress_ratio - 1.0) * 100.0 ); tr_println!( "Chunk count: {}, avg size: {}", @@ -299,7 +299,7 @@ fn print_repoinfo(info: &RepositoryInfo) { tr_println!("Bundles: {}", info.bundle_count); tr_println!("Total size: {}", to_file_size(info.encoded_data_size)); tr_println!("Uncompressed size: {}", to_file_size(info.raw_data_size)); - tr_println!("Compression ratio: {:.1}%", info.compression_ratio * 100.0); + tr_println!("Compression ratio: {:.1}%", (info.compression_ratio - 1.0) * 100.0); tr_println!("Chunk count: {}", info.chunk_count); tr_println!( "Average chunk size: {}", @@ -346,7 +346,7 @@ fn print_bundle(bundle: &StoredBundle) { tr_println!( " - Compression: {}, ratio: {:.1}%", compression, - ratio * 100.0 + (ratio - 1.0) * 100.0 ); } @@ -436,11 +436,11 @@ pub fn run() -> Result<(), ErrorCode> { Repository::create( repo_path, &Config { - bundle_size: bundle_size, - chunker: chunker, - compression: compression, + bundle_size, + chunker, + compression, encryption: None, - hash: hash + hash }, remote_path ), @@ -559,8 +559,8 @@ pub fn run() -> Result<(), ErrorCode> { )) }; let options = BackupOptions { - same_device: same_device, - excludes: excludes + same_device, + excludes }; let result = if tar { repo.import_tarfile(&src_path) diff --git a/src/index.rs b/src/index.rs index 1489cfb..2031bc9 100644 --- a/src/index.rs +++ b/src/index.rs @@ -14,7 +14,6 @@ pub const MIN_USAGE: f64 = 0.35; pub const INITIAL_SIZE: usize = 1024; -//TODO: translate quick_error!{ #[derive(Debug)] pub enum IndexError { @@ -230,10 +229,10 @@ impl Index { max_entries: (header.capacity as f64 * MAX_USAGE) as usize, min_entries: (header.capacity as f64 * MIN_USAGE) as usize, entries: header.entries as usize, - fd: fd, - mmap: mmap, - data: data, - header: header + fd, + mmap, + data, + header }; debug_assert!(index.check().is_ok(), tr!("Inconsistent after creation")); Ok(index) @@ -276,6 +275,7 @@ impl Index { self.max_entries = (capacity as f64 * MAX_USAGE) as usize; } + #[allow(redundant_field_names)] fn reinsert(&mut self, start: usize, end: usize) -> Result<(), IndexError> { for pos in start..end { let key; diff --git a/src/mount.rs b/src/mount.rs index 10a0934..86aa100 100644 --- a/src/mount.rs +++ b/src/mount.rs @@ -113,8 +113,8 @@ impl FuseInode { kind: convert_file_type(self.inode.file_type), perm: self.inode.mode as u16, nlink: 1, - uid: uid, - gid: gid, + uid, + gid, rdev: self.inode.device.map_or( 0, |(major, minor)| (major << 8) + minor @@ -158,7 +158,7 @@ impl<'a> FuseFilesystem<'a> { pub fn new(repository: &'a mut Repository) -> Result { Ok(FuseFilesystem { next_id: 1, - repository: repository, + repository, inodes: HashMap::new() }) } @@ -222,7 +222,7 @@ impl<'a> FuseFilesystem<'a> { ) -> FuseInodeRef { self.add_inode( Inode { - name: name, + name, file_type: FileType::Directory, ..Default::default() }, @@ -240,7 +240,7 @@ impl<'a> FuseFilesystem<'a> { group_names: HashMap, ) -> FuseInodeRef { let inode = FuseInode { - inode: inode, + inode, num: self.next_id, parent: parent.clone(), chunks: None, diff --git a/src/repository/backup_file.rs b/src/repository/backup_file.rs index 415a07a..767c8f2 100644 --- a/src/repository/backup_file.rs +++ b/src/repository/backup_file.rs @@ -164,7 +164,7 @@ impl Backup { try!(file.write_all(&[HEADER_VERSION]).map_err(|err| { BackupFileError::Write(err, path.to_path_buf()) })); - let header = BackupHeader { encryption: encryption }; + let header = BackupHeader { encryption }; try!(msgpack::encode_to_stream(&header, &mut file).context(path)); try!(file.write_all(&data).map_err(|err| { BackupFileError::Write(err, path.to_path_buf()) diff --git a/src/repository/basic_io.rs b/src/repository/basic_io.rs index 0609d75..b5d4478 100644 --- a/src/repository/basic_io.rs +++ b/src/repository/basic_io.rs @@ -16,7 +16,7 @@ pub struct ChunkReader<'a> { impl<'a> ChunkReader<'a> { pub fn new(repo: &'a mut Repository, chunks: ChunkList) -> Self { ChunkReader { - repo: repo, + repo, chunks: chunks.into_inner().into(), data: vec![], pos: 0 diff --git a/src/repository/config.rs b/src/repository/config.rs index 850f65c..a0d414e 100644 --- a/src/repository/config.rs +++ b/src/repository/config.rs @@ -193,8 +193,8 @@ impl Config { None }; Ok(Config { - compression: compression, - encryption: encryption, + compression, + encryption, bundle_size: yaml.bundle_size, 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 9840b45..9717928 100644 --- a/src/repository/info.rs +++ b/src/repository/info.rs @@ -137,9 +137,9 @@ impl Repository { let chunk_count = bundles.iter().map(|b| b.chunk_count).sum(); RepositoryInfo { bundle_count: bundles.len(), - chunk_count: chunk_count, - encoded_data_size: encoded_data_size, - raw_data_size: raw_data_size, + chunk_count, + encoded_data_size, + raw_data_size, compression_ratio: encoded_data_size as f32 / raw_data_size as f32, avg_chunk_size: raw_data_size as f32 / chunk_count as f32, index_size: self.index.size(), diff --git a/src/repository/mod.rs b/src/repository/mod.rs index f537865..301932d 100644 --- a/src/repository/mod.rs +++ b/src/repository/mod.rs @@ -47,8 +47,8 @@ pub struct Location { impl Location { pub fn new(bundle: u32, chunk: u32) -> Self { Location { - bundle: bundle, - chunk: chunk + bundle, + chunk } } } @@ -158,21 +158,21 @@ impl Repository { }; let dirty = layout.dirtyfile_path().exists(); let mut repo = Repository { - layout: layout, + layout, dirty: true, chunker: config.chunker.create(), - config: config, - index: index, - crypto: crypto, - bundle_map: bundle_map, + config, + index, + crypto, + bundle_map, next_data_bundle: 0, next_meta_bundle: 0, - bundles: bundles, + bundles, data_bundle: None, meta_bundle: None, - lock: lock, - remote_locks: remote_locks, - local_locks: local_locks + lock, + remote_locks, + local_locks }; if !rebuild_bundle_map { let mut save_bundle_map = false; diff --git a/src/repository/tarfile.rs b/src/repository/tarfile.rs index 2414686..ccb1586 100644 --- a/src/repository/tarfile.rs +++ b/src/repository/tarfile.rs @@ -93,7 +93,7 @@ fn inode_from_entry(entry: &mut tar::Entry) -> Result return Err(InodeError::UnsupportedFiletype(path.to_path_buf()).into()), }; Inode { - file_type: file_type, + file_type, name: path.file_name() .map(|s| s.to_string_lossy().to_string()) .unwrap_or_else(|| "/".to_string()), diff --git a/src/translation.rs b/src/translation.rs index 90a711e..d82acd7 100644 --- a/src/translation.rs +++ b/src/translation.rs @@ -58,11 +58,11 @@ impl<'a> MoFile<'a> { return Err(()); } Ok(MoFile{ - data: data, - count: count, - orig_pos: orig_pos, - trans_pos: trans_pos, - reorder: reorder, + data, + count, + orig_pos, + trans_pos, + reorder, i: 0 }) } diff --git a/src/util/bitmap.rs b/src/util/bitmap.rs index 615c473..40ca8c8 100644 --- a/src/util/bitmap.rs +++ b/src/util/bitmap.rs @@ -11,7 +11,7 @@ impl Bitmap { let len = (len + 7) / 8; let mut bytes = Vec::with_capacity(len); bytes.resize(len, 0); - Self { bytes: bytes } + Self { bytes } } /// Returns the number of bits in the bitmap @@ -67,7 +67,7 @@ impl Bitmap { #[inline] pub fn from_bytes(bytes: Vec) -> Self { - Self { bytes: bytes } + Self { bytes } } } diff --git a/src/util/cli.rs b/src/util/cli.rs index 37e357a..657a83b 100644 --- a/src/util/cli.rs +++ b/src/util/cli.rs @@ -56,9 +56,9 @@ impl ProgressIter { bar.message(&msg); bar.set_max_refresh_rate(Some(Duration::from_millis(100))); ProgressIter { - inner: inner, - bar: bar, - msg: msg + inner, + bar, + msg } } } diff --git a/src/util/compression.rs b/src/util/compression.rs index 0ab0e3f..1b9e127 100644 --- a/src/util/compression.rs +++ b/src/util/compression.rs @@ -93,8 +93,8 @@ impl Compression { _ => return Err(CompressionError::UnsupportedCodec(name.to_string())), }; Ok(Compression { - method: method, - level: level + method, + level }) } @@ -234,7 +234,7 @@ impl CompressionStream { #[inline] fn new(stream: *mut SquashStream) -> Self { CompressionStream { - stream: stream, + stream, buffer: [0; 16 * 1024] } } diff --git a/src/util/encryption.rs b/src/util/encryption.rs index ca2a5fb..391f8a9 100644 --- a/src/util/encryption.rs +++ b/src/util/encryption.rs @@ -152,7 +152,7 @@ impl Crypto { } Ok(Crypto { path: Some(path), - keys: keys + keys }) } diff --git a/src/util/hash.rs b/src/util/hash.rs index 4ee2e54..5c6fca0 100644 --- a/src/util/hash.rs +++ b/src/util/hash.rs @@ -45,8 +45,8 @@ impl Hash { let high = try!(src.read_u64::()); let low = try!(src.read_u64::()); Ok(Hash { - high: high, - low: low + high, + low }) } @@ -55,8 +55,8 @@ impl Hash { let high = try!(u64::from_str_radix(&val[..16], 16).map_err(|_| ())); let low = try!(u64::from_str_radix(&val[16..], 16).map_err(|_| ())); Ok(Self { - high: high, - low: low + high, + low }) } } diff --git a/src/util/lock.rs b/src/util/lock.rs index d2f242f..a7e828b 100644 --- a/src/util/lock.rs +++ b/src/util/lock.rs @@ -146,7 +146,7 @@ impl LockFolder { hostname: get_hostname().unwrap(), processid: unsafe { libc::getpid() } as usize, date: Utc::now().timestamp(), - exclusive: exclusive + exclusive }; let path = self.path.join(format!( "{}-{}.lock", @@ -156,7 +156,7 @@ impl LockFolder { try!(lockfile.save(&path)); let handle = LockHandle { lock: lockfile, - path: path + path }; if self.get_lock_level().is_err() { try!(handle.release()); diff --git a/src/util/lru_cache.rs b/src/util/lru_cache.rs index 4b8b9c2..e0d7049 100644 --- a/src/util/lru_cache.rs +++ b/src/util/lru_cache.rs @@ -15,8 +15,8 @@ impl LruCache { pub fn new(min_size: usize, max_size: usize) -> Self { LruCache { items: HashMap::default(), - min_size: min_size, - max_size: max_size, + min_size, + max_size, next: 0 } }