diff options
Diffstat (limited to 'src/backup_progress.rs')
-rw-r--r-- | src/backup_progress.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/backup_progress.rs b/src/backup_progress.rs index 30b6228..52430e4 100644 --- a/src/backup_progress.rs +++ b/src/backup_progress.rs @@ -1,12 +1,19 @@ +//! Progress bars for Obnam. + use crate::generation::GenId; use indicatif::{ProgressBar, ProgressStyle}; use std::path::Path; +/// A progress bar abstraction specific to backups. +/// +/// The progress bar is different for initial and incremental backups, +/// and for different phases of making a backup. pub struct BackupProgress { progress: ProgressBar, } impl BackupProgress { + /// Create a progress bar for an initial backup. pub fn initial() -> Self { let progress = if true { ProgressBar::new(0) @@ -26,6 +33,7 @@ impl BackupProgress { Self { progress } } + /// Create a progress bar for an incremental backup. pub fn incremental() -> Self { let progress = if true { ProgressBar::new(0) @@ -46,6 +54,7 @@ impl BackupProgress { Self { progress } } + /// Create a progress bar for uploading a new generation's metadata. pub fn upload_generation() -> Self { let progress = ProgressBar::new(0); let parts = vec![ @@ -59,6 +68,8 @@ impl BackupProgress { Self { progress } } + /// Create a progress bar for downloading an existing generation's + /// metadata. pub fn download_generation(gen_id: &GenId) -> Self { let progress = ProgressBar::new(0); let parts = vec!["{msg}", "elapsed: {elapsed}", "{spinner}"]; @@ -72,14 +83,21 @@ impl BackupProgress { Self { progress } } + /// Set the number of files that were in the previous generation. + /// + /// The new generation usually has about the same number of files, + /// so the progress bar can show progress for incremental backups + /// without having to count all the files that actually exist first. pub fn files_in_previous_generation(&self, count: u64) { self.progress.set_length(count); } + /// Update progress bar about number of problems found during a backup. pub fn found_problem(&self) { self.progress.inc(1); } + /// Update progress bar about number of actual files found. pub fn found_live_file(&self, filename: &Path) { self.progress.inc(1); if self.progress.length() < self.progress.position() { @@ -88,6 +106,10 @@ impl BackupProgress { self.progress.set_message(format!("{}", filename.display())); } + /// Tell progress bar it's finished. + /// + /// This will remove all traces of the progress bar from the + /// screen. pub fn finish(&self) { self.progress.set_length(self.progress.position()); self.progress.finish_and_clear(); |