From 727f59b2d3d14ba55338079201b74a527202c818 Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Sun, 2 Apr 2017 20:37:34 +0200 Subject: [PATCH] fix --- README.md | 2 -- src/cli/mod.rs | 3 +++ src/repository/backup.rs | 24 ++++++++++++++++-------- src/repository/metadata.rs | 23 ++++++++++++++--------- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 9d0b20c..c8b5886 100644 --- a/README.md +++ b/README.md @@ -109,8 +109,6 @@ Recommended: Brotli/2-7 - Random bundle name - Metadata - Arbitrarily nested chunk lists - - Cumulative size, chunk count, dir/file count -- Permissive msgpack mode ### CLI functionality - list --tree diff --git a/src/cli/mod.rs b/src/cli/mod.rs index ad742d2..f4e6452 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -105,6 +105,9 @@ fn print_inode(inode: &Inode) { if let Some(ref target) = inode.symlink_target { println!("Symlink target: {}", target); } + println!("Cumulative size: {}", to_file_size(inode.cum_size)); + println!("Cumulative file count: {}", inode.cum_files); + println!("Cumulative directory count: {}", inode.cum_dirs); if let Some(ref children) = inode.children { println!("Children:"); for name in children.keys() { diff --git a/src/repository/backup.rs b/src/repository/backup.rs index 0fff9a2..69c9b1c 100644 --- a/src/repository/backup.rs +++ b/src/repository/backup.rs @@ -158,11 +158,11 @@ impl Repository { options: &BackupOptions, backup: &mut Backup, failed_paths: &mut Vec - ) -> Result { + ) -> Result { let path = path.as_ref(); let mut inode = try!(self.create_inode(path, reference)); let meta_size = 1000; // add 1000 for encoded metadata - backup.total_data_size += inode.size + meta_size; + inode.cum_size = inode.size + meta_size; if let Some(ref_inode) = reference { if !ref_inode.is_same_meta_quick(&inode) { backup.changed_data_size += inode.size + meta_size; @@ -171,7 +171,7 @@ impl Repository { backup.changed_data_size += inode.size + meta_size; } if inode.file_type == FileType::Directory { - backup.dir_count +=1; + inode.cum_dirs = 1; let mut children = BTreeMap::new(); let parent_dev = try!(path.metadata()).st_dev(); for ch in try!(fs::read_dir(path)) { @@ -194,21 +194,25 @@ impl Repository { .and_then(|inode| inode.children.as_ref()) .and_then(|map| map.get(&name)) .and_then(|chunks| self.get_inode(chunks).ok()); - let chunks = match self.create_backup_recurse(&child_path, ref_child.as_ref(), options, backup, failed_paths) { - Ok(chunks) => chunks, + let child_inode = match self.create_backup_recurse(&child_path, ref_child.as_ref(), options, backup, failed_paths) { + Ok(inode) => inode, Err(_) => { warn!("Failed to backup {:?}", child_path); failed_paths.push(child_path); continue } }; + let chunks = try!(self.put_inode(&child_inode)); children.insert(name, chunks); + inode.cum_size += child_inode.cum_size; + inode.cum_dirs += child_inode.cum_dirs; + inode.cum_files += child_inode.cum_files; } inode.children = Some(children); } else { - backup.file_count +=1; + inode.cum_files = 1; } - self.put_inode(&inode) + Ok(inode) } #[allow(dead_code)] @@ -222,10 +226,14 @@ impl Repository { let info_before = self.info(); let start = Local::now(); let mut failed_paths = vec![]; - backup.root = try!(self.create_backup_recurse(path, reference_inode.as_ref(), options, &mut backup, &mut failed_paths)); + let root_inode = try!(self.create_backup_recurse(path, reference_inode.as_ref(), options, &mut backup, &mut failed_paths)); + backup.root = try!(self.put_inode(&root_inode)); try!(self.flush()); let elapsed = Local::now().signed_duration_since(start); backup.date = start.timestamp(); + backup.total_data_size = root_inode.cum_size; + backup.file_count = root_inode.cum_files; + backup.dir_count = root_inode.cum_dirs; backup.duration = elapsed.num_milliseconds() as f32 / 1_000.0; let info_after = self.info(); backup.deduplicated_data_size = info_after.raw_data_size - info_before.raw_data_size; diff --git a/src/repository/metadata.rs b/src/repository/metadata.rs index dc10eea..c6541c1 100644 --- a/src/repository/metadata.rs +++ b/src/repository/metadata.rs @@ -111,12 +111,13 @@ pub struct Inode { pub mode: u32, pub user: u32, pub group: u32, - pub __old_access_time: i64, pub timestamp: i64, - pub __old_create_time: i64, pub symlink_target: Option, pub contents: Option, - pub children: Option> + pub children: Option>, + pub cum_size: u64, + pub cum_dirs: usize, + pub cum_files: usize } impl Default for Inode { fn default() -> Self { @@ -127,12 +128,13 @@ impl Default for Inode { mode: 0o644, user: 1000, group: 1000, - __old_access_time: 0, timestamp: 0, - __old_create_time: 0, symlink_target: None, contents: None, - children: None + children: None, + cum_size: 0, + cum_dirs: 0, + cum_files: 0 } } } @@ -143,12 +145,15 @@ serde_impl!(Inode(u8?) { mode: u32 => 3, user: u32 => 4, group: u32 => 5, - __old_access_time: i64 => 6, + //__old_access_time: i64 => 6, timestamp: i64 => 7, - __old_create_time: i64 => 8, + //__old_create_time: i64 => 8, symlink_target: Option => 9, contents: Option => 10, - children: BTreeMap => 11 + children: BTreeMap => 11, + cum_size: u64 => 12, + cum_dirs: usize => 13, + cum_files: usize => 14 });