summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexander Batischev <eual.jp@gmail.com>2021-07-28 22:11:23 +0300
committerAlexander Batischev <eual.jp@gmail.com>2021-07-28 23:03:58 +0300
commit8f8efa64058beeeafa933c54e248fd32950ec772 (patch)
treedc3329fcd9f759bb9ef8c70b92256d78e2f4c5d7 /src
parent640f8d874d627489efe2f55333e1f9ae8120596b (diff)
downloadobnam2-8f8efa64058beeeafa933c54e248fd32950ec772.tar.gz
Store backup_roots() outcome in a struct
Diffstat (limited to 'src')
-rw-r--r--src/backup_run.rs27
-rw-r--r--src/cmd/backup.rs15
2 files changed, 30 insertions, 12 deletions
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<BackupError>,
+ /// CACHEDIR.TAG files that aren't present in in a previous generation.
+ pub new_cachedir_tags: Vec<PathBuf>,
+}
+
impl<'a> BackupRun<'a> {
pub fn initial(config: &ClientConfig, client: &'a BackupClient) -> Result<Self, BackupError> {
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<BackupError>, Vec<PathBuf>), NascentError> {
- let mut all_warnings = vec![];
+ ) -> Result<RootsBackupOutcome, NascentError> {
+ 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(())
}