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<Package>,
files: Vec<PathInfo>,
}
impl Backup {
pub fn create(config: &Config, packages: Vec<Package>) -> Result<Self> {
let mut files: Vec<PathInfo> = 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<BackupLocation>;