From ab2432645aa99bc77632a5f4d497f1b6ee65ff92 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 6 Apr 2021 09:20:03 +0300 Subject: refactor: clean up initial and incremental backup code paths a bit --- src/cmd/backup.rs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/cmd/backup.rs b/src/cmd/backup.rs index b3e77c6..e6781e9 100644 --- a/src/cmd/backup.rs +++ b/src/cmd/backup.rs @@ -7,6 +7,7 @@ use crate::fsiter::FsIterator; use crate::generation::NascentGeneration; use bytesize::MIB; use log::info; +use std::path::Path; use std::time::SystemTime; use tempfile::NamedTempFile; @@ -49,13 +50,11 @@ fn initial_backup( config: &ClientConfig, client: &BackupClient, ) -> Result<(ChunkId, i64, Vec), ObnamError> { - let run = InitialBackup::new(config, &client)?; + info!("fresh backup without a previous generation"); let newtemp = NamedTempFile::new()?; + let run = InitialBackup::new(config, &client)?; let mut all_warnings = vec![]; let count = { - println!("create nascent"); - info!("fresh backup without a previous generation"); - let mut new = NascentGeneration::create(newtemp.path())?; for root in &config.roots { let iter = FsIterator::new(root); @@ -68,10 +67,7 @@ fn initial_backup( }; run.drop(); - let progress = BackupProgress::upload_generation(); - let gen_id = client.upload_generation(newtemp.path(), SQLITE_CHUNK_SIZE)?; - progress.finish(); - + let gen_id = upload_nascent_generation(client, newtemp.path())?; Ok((gen_id, count, all_warnings)) } @@ -80,13 +76,12 @@ fn incremental_backup( config: &ClientConfig, client: &BackupClient, ) -> Result<(ChunkId, i64, Vec), ObnamError> { - let mut run = IncrementalBackup::new(config, &client)?; + info!("incremental backup based on {}", old_ref); let newtemp = NamedTempFile::new()?; + let mut run = IncrementalBackup::new(config, &client)?; let mut all_warnings = vec![]; let count = { - info!("incremental backup based on {}", old_ref); let oldtemp = NamedTempFile::new()?; - let old = run.fetch_previous_generation(old_ref, oldtemp.path())?; run.start_backup(&old)?; let mut new = NascentGeneration::create(newtemp.path())?; @@ -101,9 +96,16 @@ fn incremental_backup( }; run.drop(); + let gen_id = upload_nascent_generation(client, newtemp.path())?; + Ok((gen_id, count, all_warnings)) +} + +fn upload_nascent_generation( + client: &BackupClient, + filename: &Path, +) -> Result { let progress = BackupProgress::upload_generation(); - let gen_id = client.upload_generation(newtemp.path(), SQLITE_CHUNK_SIZE)?; + let gen_id = client.upload_generation(filename, SQLITE_CHUNK_SIZE)?; progress.finish(); - - Ok((gen_id, count, all_warnings)) + Ok(gen_id) } -- cgit v1.2.1