diff options
Diffstat (limited to 'src/policy.rs')
-rw-r--r-- | src/policy.rs | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/policy.rs b/src/policy.rs index 032b851..8cdbd76 100644 --- a/src/policy.rs +++ b/src/policy.rs @@ -1,24 +1,40 @@ +//! Policy for what gets backed up. + use crate::backup_reason::Reason; use crate::fsentry::FilesystemEntry; use crate::generation::LocalGeneration; -use log::{debug, warn}; +use log::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, } -impl BackupPolicy { - pub fn new() -> Self { +impl Default for BackupPolicy { + /// Create a default policy. + fn default() -> Self { Self { new: true, old_if_changed: true, } } +} +impl BackupPolicy { + /// Does a given file need to be backed up? pub fn needs_backup(&self, old: &LocalGeneration, new_entry: &FilesystemEntry) -> Reason { let new_name = new_entry.pathbuf(); - let reason = match old.get_file(&new_name) { + match old.get_file(&new_name) { Ok(None) => { if self.new { Reason::IsNew @@ -42,14 +58,9 @@ impl BackupPolicy { "needs_backup: lookup in old generation returned error, ignored: {:?}: {}", new_name, err ); - Reason::Error + Reason::GenerationLookupError } - }; - debug!( - "needs_backup: file {:?}: policy decision: {}", - new_name, reason - ); - reason + } } } |