From 553bbac36bdc483135a7053ca64507e01397e5e1 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Mon, 9 Sep 2024 23:03:49 +0200 Subject: add package manager recognition --- src/backup.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/backup.rs') diff --git a/src/backup.rs b/src/backup.rs index e463593..f9de139 100644 --- a/src/backup.rs +++ b/src/backup.rs @@ -12,7 +12,7 @@ use uuid::Uuid; use crate::{ config::Config, error::{Error, Result}, - packages::Package, + packages::{Manager, PackageList}, pathinfo::PathInfo, }; @@ -22,13 +22,13 @@ pub type Id = String; pub struct Backup { pub id: String, pub timestamp: u64, - packages: Vec, + pub packages: PackageList, pub files: Vec, - device: String, + pub device: String, } impl Backup { - pub fn create(config: &Config, packages: Vec) -> Result { + pub fn create(config: &Config, manager: Option) -> Result { let mut files: Vec = Vec::new(); for dir in &config.directories { files.push(PathInfo::from_path(config, dir)?); @@ -37,7 +37,7 @@ impl Backup { // TODO: UUID not really needed, maybe a shorter hash id: Uuid::new_v4().to_string(), timestamp: Self::get_timestamp(), - packages, + packages: Manager::get_manager(manager)?.get_installed()?, files, device: config.device.clone(), }) @@ -62,6 +62,7 @@ impl Backup { pub fn get_last(config: &Config) -> Result> { let backup_index_root = format!("{}/index.json", config.root); + info!(?backup_index_root, "backup index location:"); let list: Vec = match Self::get_json_content(&backup_index_root) { Ok(list) => list, Err(err) => { @@ -72,6 +73,8 @@ impl Backup { } }; + info!(?list, "backup index:"); + Ok(Some(Self::from_index( config, &list.last().ok_or(Error::BackupNotFound)?.id, @@ -109,6 +112,10 @@ impl Backup { format!("{loc}/{rel_location}") } + pub fn restore(&self) { + todo!() + } + fn get_json_content Deserialize<'a>>(path: &str) -> Result { let mut file = File::open(path)?; let mut content = String::new(); -- cgit v1.2.3