diff options
Diffstat (limited to 'src/backup.rs')
-rw-r--r-- | src/backup.rs | 17 |
1 files changed, 12 insertions, 5 deletions
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; | |||
12 | use crate::{ | 12 | use crate::{ |
13 | config::Config, | 13 | config::Config, |
14 | error::{Error, Result}, | 14 | error::{Error, Result}, |
15 | packages::Package, | 15 | packages::{Manager, PackageList}, |
16 | pathinfo::PathInfo, | 16 | pathinfo::PathInfo, |
17 | }; | 17 | }; |
18 | 18 | ||
@@ -22,13 +22,13 @@ pub type Id = String; | |||
22 | pub struct Backup { | 22 | pub struct Backup { |
23 | pub id: String, | 23 | pub id: String, |
24 | pub timestamp: u64, | 24 | pub timestamp: u64, |
25 | packages: Vec<Package>, | 25 | pub packages: PackageList, |
26 | pub files: Vec<PathInfo>, | 26 | pub files: Vec<PathInfo>, |
27 | device: String, | 27 | pub device: String, |
28 | } | 28 | } |
29 | 29 | ||
30 | impl Backup { | 30 | impl Backup { |
31 | pub fn create(config: &Config, packages: Vec<Package>) -> Result<Self> { | 31 | pub fn create(config: &Config, manager: Option<Manager>) -> Result<Self> { |
32 | let mut files: Vec<PathInfo> = Vec::new(); | 32 | let mut files: Vec<PathInfo> = Vec::new(); |
33 | for dir in &config.directories { | 33 | for dir in &config.directories { |
34 | files.push(PathInfo::from_path(config, dir)?); | 34 | files.push(PathInfo::from_path(config, dir)?); |
@@ -37,7 +37,7 @@ impl Backup { | |||
37 | // TODO: UUID not really needed, maybe a shorter hash | 37 | // TODO: UUID not really needed, maybe a shorter hash |
38 | id: Uuid::new_v4().to_string(), | 38 | id: Uuid::new_v4().to_string(), |
39 | timestamp: Self::get_timestamp(), | 39 | timestamp: Self::get_timestamp(), |
40 | packages, | 40 | packages: Manager::get_manager(manager)?.get_installed()?, |
41 | files, | 41 | files, |
42 | device: config.device.clone(), | 42 | device: config.device.clone(), |
43 | }) | 43 | }) |
@@ -62,6 +62,7 @@ impl Backup { | |||
62 | 62 | ||
63 | pub fn get_last(config: &Config) -> Result<Option<Self>> { | 63 | pub fn get_last(config: &Config) -> Result<Option<Self>> { |
64 | let backup_index_root = format!("{}/index.json", config.root); | 64 | let backup_index_root = format!("{}/index.json", config.root); |
65 | info!(?backup_index_root, "backup index location:"); | ||
65 | let list: Vec<IndexEntry> = match Self::get_json_content(&backup_index_root) { | 66 | let list: Vec<IndexEntry> = match Self::get_json_content(&backup_index_root) { |
66 | Ok(list) => list, | 67 | Ok(list) => list, |
67 | Err(err) => { | 68 | Err(err) => { |
@@ -72,6 +73,8 @@ impl Backup { | |||
72 | } | 73 | } |
73 | }; | 74 | }; |
74 | 75 | ||
76 | info!(?list, "backup index:"); | ||
77 | |||
75 | Ok(Some(Self::from_index( | 78 | Ok(Some(Self::from_index( |
76 | config, | 79 | config, |
77 | &list.last().ok_or(Error::BackupNotFound)?.id, | 80 | &list.last().ok_or(Error::BackupNotFound)?.id, |
@@ -109,6 +112,10 @@ impl Backup { | |||
109 | format!("{loc}/{rel_location}") | 112 | format!("{loc}/{rel_location}") |
110 | } | 113 | } |
111 | 114 | ||
115 | pub fn restore(&self) { | ||
116 | todo!() | ||
117 | } | ||
118 | |||
112 | fn get_json_content<T: for<'a> Deserialize<'a>>(path: &str) -> Result<T> { | 119 | fn get_json_content<T: for<'a> Deserialize<'a>>(path: &str) -> Result<T> { |
113 | let mut file = File::open(path)?; | 120 | let mut file = File::open(path)?; |
114 | let mut content = String::new(); | 121 | let mut content = String::new(); |