summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Batischev <eual.jp@gmail.com>2021-07-21 21:26:05 +0300
committerAlexander Batischev <eual.jp@gmail.com>2021-07-21 22:25:47 +0300
commit24a3284979e41405e213f031ccfcca3f6f1513eb (patch)
tree240ae29c62be7a4bf2abdb53c1b0fc2214514216
parent90e8f2dbf2f87a6a8fef8d44801642d9c644050f (diff)
downloadobnam2-24a3284979e41405e213f031ccfcca3f6f1513eb.tar.gz
backup_run: replace tuple with a struct
-rw-r--r--src/backup_run.rs26
-rw-r--r--src/generation.rs8
2 files changed, 25 insertions, 9 deletions
diff --git a/src/backup_run.rs b/src/backup_run.rs
index ccbf640..6c3a4f2 100644
--- a/src/backup_run.rs
+++ b/src/backup_run.rs
@@ -30,6 +30,13 @@ pub enum BackupError {
LocalGenerationError(#[from] LocalGenerationError),
}
+#[derive(Debug)]
+pub struct FsEntryBackupOutcome {
+ pub entry: FilesystemEntry,
+ pub ids: Vec<ChunkId>,
+ pub reason: Reason,
+}
+
impl<'a> BackupRun<'a> {
pub fn initial(config: &ClientConfig, client: &'a BackupClient) -> Result<Self, BackupError> {
Ok(Self {
@@ -108,11 +115,12 @@ impl<'a> BackupRun<'a> {
self.finish();
Ok((count, all_warnings))
}
+
pub fn backup(
&self,
entry: FsIterResult<FilesystemEntry>,
old: &LocalGeneration,
- ) -> Result<(FilesystemEntry, Vec<ChunkId>, Reason), BackupError> {
+ ) -> Result<FsEntryBackupOutcome, BackupError> {
match entry {
Err(err) => {
warn!("backup: {}", err);
@@ -146,7 +154,7 @@ impl<'a> BackupRun<'a> {
} else {
vec![]
};
- Ok((entry, ids, reason))
+ Ok(FsEntryBackupOutcome { entry, ids, reason })
}
}
}
@@ -168,13 +176,21 @@ fn backup_file(
path: &Path,
chunk_size: usize,
reason: Reason,
-) -> (FilesystemEntry, Vec<ChunkId>, Reason) {
+) -> FsEntryBackupOutcome {
let ids = client.upload_filesystem_entry(&entry, chunk_size);
match ids {
Err(err) => {
warn!("error backing up {}, skipping it: {}", path.display(), err);
- (entry.clone(), vec![], Reason::FileError)
+ FsEntryBackupOutcome {
+ entry: entry.clone(),
+ ids: vec![],
+ reason: Reason::FileError,
+ }
}
- Ok(ids) => (entry.clone(), ids, reason),
+ Ok(ids) => FsEntryBackupOutcome {
+ entry: entry.clone(),
+ ids,
+ reason,
+ },
}
}
diff --git a/src/generation.rs b/src/generation.rs
index f4e4f53..893d23b 100644
--- a/src/generation.rs
+++ b/src/generation.rs
@@ -1,5 +1,5 @@
use crate::backup_reason::Reason;
-use crate::backup_run::BackupError;
+use crate::backup_run::{BackupError, FsEntryBackupOutcome};
use crate::chunkid::ChunkId;
use crate::fsentry::FilesystemEntry;
use log::debug;
@@ -67,7 +67,7 @@ impl NascentGeneration {
pub fn insert_iter(
&mut self,
- entries: impl Iterator<Item = Result<(FilesystemEntry, Vec<ChunkId>, Reason), BackupError>>,
+ entries: impl Iterator<Item = Result<FsEntryBackupOutcome, BackupError>>,
) -> NascentResult<Vec<BackupError>> {
let t = self.conn.transaction().map_err(NascentError::Transaction)?;
let mut warnings = vec![];
@@ -77,9 +77,9 @@ impl NascentGeneration {
debug!("ignoring backup error {}", err);
warnings.push(err);
}
- Ok((e, ids, reason)) => {
+ Ok(FsEntryBackupOutcome { entry, ids, reason }) => {
self.fileno += 1;
- sql::insert_one(&t, e, self.fileno, &ids[..], reason)?;
+ sql::insert_one(&t, entry, self.fileno, &ids[..], reason)?;
}
}
}