From 3e1cb020d5449849b37874f91cadfa4a9c878747 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Fri, 6 Sep 2024 10:56:30 +0200 Subject: initial commit, can save index, no modification check --- src/backup.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/backup.rs (limited to 'src/backup.rs') diff --git a/src/backup.rs b/src/backup.rs new file mode 100644 index 0000000..4e74c97 --- /dev/null +++ b/src/backup.rs @@ -0,0 +1,44 @@ +use std::time::{SystemTime, UNIX_EPOCH}; + +use serde::{Deserialize, Serialize}; +use uuid::Uuid; + +use crate::{config::Config, pathinfo::PathInfo, packages::Package, error::Result}; + +pub type BackupId = String; + +#[derive(Debug, Serialize, Deserialize)] +pub struct Backup { + id: String, + timestamp: u64, + packages: Vec, + files: Vec, +} + +impl Backup { + pub fn create(config: &Config, packages: Vec) -> Result { + let mut files: Vec = Vec::new(); + for dir in &config.directories { + files.push(PathInfo::from_path(config, dir)?); + } + Ok(Self { + // UUID not really needed, maybe a shorter hash + id: Uuid::new_v4().to_string(), + timestamp: SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_secs(), + packages, + files, + }) + } + + +} + +struct BackupLocation { + id: BackupId, + rel_location: String, +} + +type BackupList = Vec; -- cgit v1.2.3