From 8f8efa64058beeeafa933c54e248fd32950ec772 Mon Sep 17 00:00:00 2001 From: Alexander Batischev Date: Wed, 28 Jul 2021 22:11:23 +0300 Subject: Store backup_roots() outcome in a struct --- src/backup_run.rs | 27 ++++++++++++++++++++------- src/cmd/backup.rs | 15 ++++++++++----- 2 files changed, 30 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/backup_run.rs b/src/backup_run.rs index b01b365..738830d 100644 --- a/src/backup_run.rs +++ b/src/backup_run.rs @@ -38,6 +38,16 @@ pub struct FsEntryBackupOutcome { pub is_cachedir_tag: bool, } +#[derive(Debug)] +pub struct RootsBackupOutcome { + /// The number of backed up files. + pub files_count: i64, + /// The errors encountered while backing up files. + pub warnings: Vec, + /// CACHEDIR.TAG files that aren't present in in a previous generation. + pub new_cachedir_tags: Vec, +} + impl<'a> BackupRun<'a> { pub fn initial(config: &ClientConfig, client: &'a BackupClient) -> Result { Ok(Self { @@ -102,11 +112,10 @@ impl<'a> BackupRun<'a> { config: &ClientConfig, old: &LocalGeneration, newpath: &Path, - // TODO: turn this tuple into a struct for readability - ) -> Result<(i64, Vec, Vec), NascentError> { - let mut all_warnings = vec![]; + ) -> Result { + let mut warnings = vec![]; let mut new_cachedir_tags = vec![]; - let count = { + let files_count = { let mut new = NascentGeneration::create(newpath)?; for root in &config.roots { let iter = FsIterator::new(root, config.exclude_cache_tag_directories); @@ -119,13 +128,17 @@ impl<'a> BackupRun<'a> { }; self.backup(entry, &old) }); - let mut warnings = new.insert_iter(entries)?; - all_warnings.append(&mut warnings); + let mut new_warnings = new.insert_iter(entries)?; + warnings.append(&mut new_warnings); } new.file_count() }; self.finish(); - Ok((count, all_warnings, new_cachedir_tags)) + Ok(RootsBackupOutcome { + files_count, + warnings, + new_cachedir_tags, + }) } pub fn backup( diff --git a/src/cmd/backup.rs b/src/cmd/backup.rs index 6777856..496477e 100644 --- a/src/cmd/backup.rs +++ b/src/cmd/backup.rs @@ -26,7 +26,7 @@ impl Backup { let oldtemp = NamedTempFile::new()?; let newtemp = NamedTempFile::new()?; - let (is_incremental, (count, warnings, new_tags)) = match genlist.resolve("latest") { + let (is_incremental, outcome) = match genlist.resolve("latest") { Err(_) => { info!("fresh backup without a previous generation"); let mut run = BackupRun::initial(config, &client)?; @@ -43,19 +43,24 @@ impl Backup { let gen_id = upload_nascent_generation(&client, newtemp.path())?; - for w in warnings.iter() { + for w in outcome.warnings.iter() { println!("warning: {}", w); } - if is_incremental && !new_tags.is_empty() { + if is_incremental && !outcome.new_cachedir_tags.is_empty() { println!("New CACHEDIR.TAG files since the last backup:"); - for t in new_tags { + for t in outcome.new_cachedir_tags { println!("- {:?}", t); } println!("You can configure Obnam to ignore all such files by setting `exclude_cache_tag_directories` to `false`."); } - report_stats(&runtime, count, &gen_id, warnings.len())?; + report_stats( + &runtime, + outcome.files_count, + &gen_id, + outcome.warnings.len(), + )?; Ok(()) } -- cgit v1.2.1