summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-08-09 10:33:39 +0300
committerLars Wirzenius <liw@liw.fi>2021-08-09 10:33:39 +0300
commit06755358f8e8192d75be8dc250fe49066a8d75ac (patch)
treefaa948e949364425a74045418108481499912ddf /src
parent6e9a1f5f45a5608a05931fd4d579c8ab52316f55 (diff)
downloadobnam2-06755358f8e8192d75be8dc250fe49066a8d75ac.tar.gz
refactor: split long func into two
Sponsored-by: author
Diffstat (limited to 'src')
-rw-r--r--src/backup_progress.rs4
-rw-r--r--src/backup_run.rs93
2 files changed, 69 insertions, 28 deletions
diff --git a/src/backup_progress.rs b/src/backup_progress.rs
index 30b6228..741ae7c 100644
--- a/src/backup_progress.rs
+++ b/src/backup_progress.rs
@@ -80,6 +80,10 @@ impl BackupProgress {
self.progress.inc(1);
}
+ pub fn found_problems(&self, n: u64) {
+ self.progress.inc(n);
+ }
+
pub fn found_live_file(&self, filename: &Path) {
self.progress.inc(1);
if self.progress.length() < self.progress.position() {
diff --git a/src/backup_run.rs b/src/backup_run.rs
index 39ef217..e3bf4b2 100644
--- a/src/backup_run.rs
+++ b/src/backup_run.rs
@@ -131,44 +131,75 @@ impl<'a> BackupRun<'a> {
let files_count = {
let mut new = NascentGeneration::create(newpath)?;
for root in &config.roots {
- let iter = FsIterator::new(root, config.exclude_cache_tag_directories);
- for entry in iter {
- match entry {
+ match self.backup_one_root(config, old, &mut new, root).await {
+ Ok(mut o) => {
+ new_cachedir_tags.append(&mut o.new_cachedir_tags);
+ if !o.warnings.is_empty() {
+ warnings.append(&mut o.warnings);
+ self.found_problems(o.warnings.len() as u64);
+ }
+ }
+ Err(err) => {
+ debug!("ignoring backup error {}", err);
+ warnings.push(err.into());
+ self.found_problem();
+ }
+ }
+ }
+ new.file_count()
+ };
+ self.finish();
+ Ok(RootsBackupOutcome {
+ files_count,
+ warnings,
+ new_cachedir_tags,
+ })
+ }
+
+ async fn backup_one_root(
+ &self,
+ config: &ClientConfig,
+ old: &LocalGeneration,
+ new: &mut NascentGeneration,
+ root: &Path,
+ ) -> Result<RootsBackupOutcome, NascentError> {
+ let mut warnings: Vec<BackupError> = vec![];
+ let mut new_cachedir_tags = vec![];
+ let iter = FsIterator::new(root, config.exclude_cache_tag_directories);
+ for entry in iter {
+ match entry {
+ Err(err) => {
+ debug!("ignoring backup error {}", err);
+ warnings.push(err.into());
+ self.found_problem();
+ }
+ Ok(entry) => {
+ let path = entry.inner.pathbuf();
+ if entry.is_cachedir_tag && !old.is_cachedir_tag(&path)? {
+ new_cachedir_tags.push(path);
+ }
+ match self.backup(entry, old).await {
Err(err) => {
debug!("ignoring backup error {}", err);
- warnings.push(err.into());
+ warnings.push(err);
self.found_problem();
}
- Ok(entry) => {
- let path = entry.inner.pathbuf();
- if entry.is_cachedir_tag && !old.is_cachedir_tag(&path)? {
- new_cachedir_tags.push(path);
- }
- match self.backup(entry, old).await {
- Err(err) => {
- debug!("ignoring backup error {}", err);
- warnings.push(err);
- self.found_problem();
- }
- Ok(o) => {
- if let Err(err) =
- new.insert(o.entry, &o.ids, o.reason, o.is_cachedir_tag)
- {
- debug!("ignoring backup error {}", err);
- warnings.push(err.into());
- self.found_problem();
- }
- }
+ Ok(o) => {
+ if let Err(err) =
+ new.insert(o.entry, &o.ids, o.reason, o.is_cachedir_tag)
+ {
+ debug!("ignoring backup error {}", err);
+ warnings.push(err.into());
+ self.found_problem();
}
}
}
}
}
- new.file_count()
- };
- self.finish();
+ }
+
Ok(RootsBackupOutcome {
- files_count,
+ files_count: 0, // Caller will get file count from new.
warnings,
new_cachedir_tags,
})
@@ -219,6 +250,12 @@ impl<'a> BackupRun<'a> {
progress.found_problem();
}
}
+
+ fn found_problems(&self, n: u64) {
+ if let Some(progress) = &self.progress {
+ progress.found_problems(n);
+ }
+ }
}
async fn backup_file(