From 34bbdc7fc0ad76105146ccb2e62be1ad6164f7ef Mon Sep 17 00:00:00 2001 From: Alexander Batischev Date: Tue, 3 Aug 2021 16:01:10 +0300 Subject: fix: do not overlap "download" and "incremental" progress bars The problem is the same as #101, except this time it affected a different set of progress bars. It was introduced in e6147a3b7b58b151fb7ad9b1f748e0a666f271de. This commit postpones the creation of "incremental" progress bar until after we've fetched the previous generation. This avoids showing both progress bars at once. --- src/backup_run.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/backup_run.rs b/src/backup_run.rs index dee1d11..7172201 100644 --- a/src/backup_run.rs +++ b/src/backup_run.rs @@ -15,7 +15,7 @@ pub struct BackupRun<'a> { client: &'a BackupClient, policy: BackupPolicy, buffer_size: usize, - progress: BackupProgress, + progress: Option, } #[derive(Debug, thiserror::Error)] @@ -54,7 +54,7 @@ impl<'a> BackupRun<'a> { client, policy: BackupPolicy::default(), buffer_size: config.chunk_size, - progress: BackupProgress::initial(), + progress: Some(BackupProgress::initial()), }) } @@ -66,7 +66,7 @@ impl<'a> BackupRun<'a> { client, policy: BackupPolicy::default(), buffer_size: config.chunk_size, - progress: BackupProgress::incremental(), + progress: None, }) } @@ -85,8 +85,11 @@ impl<'a> BackupRun<'a> { } Some(genid) => { let old = self.fetch_previous_generation(genid, oldname)?; - self.progress - .files_in_previous_generation(old.file_count()? as u64); + + let progress = BackupProgress::incremental(); + progress.files_in_previous_generation(old.file_count()? as u64); + self.progress = Some(progress); + Ok(old) } } @@ -104,7 +107,9 @@ impl<'a> BackupRun<'a> { } pub fn finish(&self) { - self.progress.finish(); + if let Some(progress) = &self.progress { + progress.finish(); + } } pub fn backup_roots( @@ -192,11 +197,15 @@ impl<'a> BackupRun<'a> { } fn found_live_file(&self, path: &Path) { - self.progress.found_live_file(path); + if let Some(progress) = &self.progress { + progress.found_live_file(path); + } } fn found_problem(&self) { - self.progress.found_problem(); + if let Some(progress) = &self.progress { + progress.found_problem(); + } } } -- cgit v1.2.1