diff options
-rw-r--r-- | src/backup_reason.rs | 3 | ||||
-rw-r--r-- | src/backup_run.rs | 4 | ||||
-rw-r--r-- | src/chunker.rs | 6 | ||||
-rw-r--r-- | src/policy.rs | 9 |
4 files changed, 16 insertions, 6 deletions
diff --git a/src/backup_reason.rs b/src/backup_reason.rs index 590f470..9a17d80 100644 --- a/src/backup_reason.rs +++ b/src/backup_reason.rs @@ -7,7 +7,8 @@ use std::fmt; /// Represent the reason a file is in a backup. #[derive(Debug, Copy, Clone)] pub enum Reason { - /// File was skipped for some reason, but carried over without changes. + /// File was skipped due to policy, but carried over without + /// changes. Skipped, /// File is new, compared to previous backup. IsNew, diff --git a/src/backup_run.rs b/src/backup_run.rs index bb7568f..0b816bf 100644 --- a/src/backup_run.rs +++ b/src/backup_run.rs @@ -3,7 +3,7 @@ use crate::backup_progress::BackupProgress; use crate::backup_reason::Reason; use crate::chunk::{GenerationChunk, GenerationChunkError}; -use crate::chunker::{Chunker, ChunkerError}; +use crate::chunker::{ChunkerError, FileChunks}; use crate::chunkid::ChunkId; use crate::client::{BackupClient, ClientError}; use crate::config::ClientConfig; @@ -360,7 +360,7 @@ impl<'a> BackupRun<'a> { let mut chunk_ids = vec![]; let file = std::fs::File::open(filename) .map_err(|err| ClientError::FileOpen(filename.to_path_buf(), err))?; - let chunker = Chunker::new(size, file, filename); + let chunker = FileChunks::new(size, file, filename); for item in chunker { let chunk = item?; if let Some(chunk_id) = self.client.has_chunk(chunk.meta()).await? { diff --git a/src/chunker.rs b/src/chunker.rs index e8e31e1..7954621 100644 --- a/src/chunker.rs +++ b/src/chunker.rs @@ -7,7 +7,7 @@ use std::io::prelude::*; use std::path::{Path, PathBuf}; /// Iterator over chunks in a file. -pub struct Chunker { +pub struct FileChunks { chunk_size: usize, buf: Vec<u8>, filename: PathBuf, @@ -22,7 +22,7 @@ pub enum ChunkerError { FileRead(PathBuf, std::io::Error), } -impl Chunker { +impl FileChunks { /// Create new iterator. pub fn new(chunk_size: usize, handle: std::fs::File, filename: &Path) -> Self { let mut buf = vec![]; @@ -61,7 +61,7 @@ impl Chunker { } } -impl Iterator for Chunker { +impl Iterator for FileChunks { type Item = Result<DataChunk, ChunkerError>; /// Return the next chunk, if any, or an error. diff --git a/src/policy.rs b/src/policy.rs index 9b66c1d..7241f0f 100644 --- a/src/policy.rs +++ b/src/policy.rs @@ -6,6 +6,15 @@ use crate::generation::LocalGeneration; use log::{debug, warn}; /// Policy for what gets backed up. +/// +/// The policy allows two aspects to be controlled: +/// +/// * should new files )(files that didn't exist in the previous +/// backup be included in the new backup? +/// * should files that haven't been changed since the previous backup +/// be included in the new backup? +/// +/// If policy doesn't allow a file to be included, it's skipped. pub struct BackupPolicy { new: bool, old_if_changed: bool, |