summaryrefslogtreecommitdiff
path: root/src/backup_reason.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/backup_reason.rs')
-rw-r--r--src/backup_reason.rs36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/backup_reason.rs b/src/backup_reason.rs
index 218857c..9a17d80 100644
--- a/src/backup_reason.rs
+++ b/src/backup_reason.rs
@@ -1,29 +1,54 @@
+//! Why was a file backed up?
+
use rusqlite::types::ToSqlOutput;
use rusqlite::ToSql;
use std::fmt;
+/// Represent the reason a file is in a backup.
#[derive(Debug, Copy, Clone)]
pub enum Reason {
+ /// File was skipped due to policy, but carried over without
+ /// changes.
Skipped,
+ /// File is new, compared to previous backup.
IsNew,
+ /// File has been changed, compared to previous backup,
Changed,
+ /// File has not been changed, compared to previous backup,
Unchanged,
- Error,
+ /// There was an error looking up the file in the previous backup.
+ ///
+ /// File has been carried over without changes.
+ GenerationLookupError,
+ /// The was an error backing up the file.
+ ///
+ /// File has been carried over without changes.
+ FileError,
+ /// Reason is unknown.
+ ///
+ /// The previous backup had a reason that the current version of
+ /// Obnam doesn't recognize. The file has been carried over
+ /// without changes.
+ Unknown,
}
impl Reason {
- pub fn from_str(text: &str) -> Reason {
+ /// Create a Reason from a string representation.
+ pub fn from(text: &str) -> Reason {
match text {
"skipped" => Reason::Skipped,
"new" => Reason::IsNew,
"changed" => Reason::Changed,
"unchanged" => Reason::Unchanged,
- _ => Reason::Error,
+ "genlookuperror" => Reason::GenerationLookupError,
+ "fileerror" => Reason::FileError,
+ _ => Reason::Unknown,
}
}
}
impl ToSql for Reason {
+ /// Represent Reason as text for SQL.
fn to_sql(&self) -> rusqlite::Result<ToSqlOutput> {
Ok(ToSqlOutput::Owned(rusqlite::types::Value::Text(format!(
"{}",
@@ -33,13 +58,16 @@ impl ToSql for Reason {
}
impl fmt::Display for Reason {
+ /// Represent Reason for display.
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let reason = match self {
Reason::Skipped => "skipped",
Reason::IsNew => "new",
Reason::Changed => "changed",
Reason::Unchanged => "unchanged",
- Reason::Error => "error",
+ Reason::GenerationLookupError => "genlookuperror",
+ Reason::FileError => "fileerror",
+ Reason::Unknown => "unknown",
};
write!(f, "{}", reason)
}