diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-02-07 18:03:16 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-02-07 18:45:29 +0200 |
commit | 3ef5bd7a3ab445509216116bb2f8009ace2b1080 (patch) | |
tree | f9a176737e6b79f9c6977bdf98090041bca2f01e /src/backup_run.rs | |
parent | 5b863edb32314808b6823f90c03ad97da6fdbcbf (diff) | |
download | obnam2-3ef5bd7a3ab445509216116bb2f8009ace2b1080.tar.gz |
feat: if file can't be read, log that, don't end backup in error
Such files won't be restored, as they'd be restored as empty file, and
that would be confusing and thus bad.
Diffstat (limited to 'src/backup_run.rs')
-rw-r--r-- | src/backup_run.rs | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/src/backup_run.rs b/src/backup_run.rs index e0ed533..7bb4440 100644 --- a/src/backup_run.rs +++ b/src/backup_run.rs @@ -7,6 +7,7 @@ use crate::fsiter::{FsIterError, FsIterResult}; use crate::generation::{LocalGeneration, LocalGenerationError}; use crate::policy::BackupPolicy; use log::{info, warn}; +use std::path::Path; pub struct BackupRun { client: BackupClient, @@ -60,10 +61,7 @@ impl BackupRun { let path = &entry.pathbuf(); info!("backup: {}", path.display()); self.progress.found_live_file(path); - let ids = self - .client - .upload_filesystem_entry(&entry, self.buffer_size)?; - Ok((entry.clone(), ids, Reason::IsNew)) + backup_file(&self.client, &entry, &path, self.buffer_size, Reason::IsNew) } } } @@ -89,12 +87,9 @@ impl BackupRun { | Reason::Changed | Reason::GenerationLookupError | Reason::Unknown => { - let ids = self - .client - .upload_filesystem_entry(&entry, self.buffer_size)?; - Ok((entry.clone(), ids, reason)) + backup_file(&self.client, &entry, &path, self.buffer_size, reason) } - Reason::Unchanged | Reason::Skipped => { + Reason::Unchanged | Reason::Skipped | Reason::FileError => { let fileno = old.get_fileno(&entry.pathbuf())?; let ids = if let Some(fileno) = fileno { old.chunkids(fileno)? @@ -108,3 +103,20 @@ impl BackupRun { } } } + +fn backup_file( + client: &BackupClient, + entry: &FilesystemEntry, + path: &Path, + chunk_size: usize, + reason: Reason, +) -> BackupResult<(FilesystemEntry, Vec<ChunkId>, Reason)> { + let ids = client.upload_filesystem_entry(&entry, chunk_size); + match ids { + Err(err) => { + warn!("error backing up {}, skipping it: {}", path.display(), err); + Ok((entry.clone(), vec![], Reason::FileError)) + } + Ok(ids) => Ok((entry.clone(), ids, reason)), + } +} |