summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/backup.rs8
-rw-r--r--src/pathinfo.rs24
2 files changed, 20 insertions, 12 deletions
diff --git a/src/backup.rs b/src/backup.rs
index a643cb2..675f020 100644
--- a/src/backup.rs
+++ b/src/backup.rs
@@ -20,7 +20,7 @@ pub type BackupId = String;
20#[derive(Debug, Serialize, Deserialize)] 20#[derive(Debug, Serialize, Deserialize)]
21pub struct Backup { 21pub struct Backup {
22 pub id: String, 22 pub id: String,
23 timestamp: u64, 23 pub timestamp: u64,
24 packages: Vec<Package>, 24 packages: Vec<Package>,
25 pub files: Vec<PathInfo>, 25 pub files: Vec<PathInfo>,
26 device: String, 26 device: String,
@@ -74,16 +74,16 @@ impl Backup {
74 74
75 Ok(Some(Self::from_index( 75 Ok(Some(Self::from_index(
76 config, 76 config,
77 list.last().ok_or(Error::BackupNotFound)?.id.clone(), 77 &list.last().ok_or(Error::BackupNotFound)?.id,
78 )?)) 78 )?))
79 } 79 }
80 80
81 pub fn from_index(config: &Config, id: BackupId) -> Result<Self> { 81 pub fn from_index(config: &Config, id: &BackupId) -> Result<Self> {
82 let backup_index_root = format!("{}/index.json", config.root); 82 let backup_index_root = format!("{}/index.json", config.root);
83 let list: Vec<BackupLocation> = Self::get_json_content(&backup_index_root)?; 83 let list: Vec<BackupLocation> = Self::get_json_content(&backup_index_root)?;
84 let index_loc = list 84 let index_loc = list
85 .iter() 85 .iter()
86 .find(|bl| bl.id == id) 86 .find(|bl| &bl.id == id)
87 .ok_or(Error::BackupNotFound)? 87 .ok_or(Error::BackupNotFound)?
88 .rel_location 88 .rel_location
89 .clone(); 89 .clone();
diff --git a/src/pathinfo.rs b/src/pathinfo.rs
index 3e4b5c2..212dd2a 100644
--- a/src/pathinfo.rs
+++ b/src/pathinfo.rs
@@ -15,11 +15,11 @@ use crate::{
15 15
16#[derive(Debug, Clone, Serialize, Deserialize)] 16#[derive(Debug, Clone, Serialize, Deserialize)]
17pub struct PathInfo { 17pub struct PathInfo {
18 pub is_file: bool, 18 is_file: bool,
19 rel_location: String, 19 rel_location: String,
20 location_root: LocationRoot, 20 location_root: LocationRoot,
21 last_modified: Option<BackupId>, 21 last_modified: Option<BackupId>,
22 pub children: Vec<PathInfo>, 22 children: Vec<PathInfo>,
23} 23}
24 24
25impl PathInfo { 25impl PathInfo {
@@ -37,7 +37,9 @@ impl PathInfo {
37 println!("Handling {rel_location}"); 37 println!("Handling {rel_location}");
38 let path = Self::get_abs_path(&location_root.to_string(), rel_location); 38 let path = Self::get_abs_path(&location_root.to_string(), rel_location);
39 Ok(if path.is_dir() { 39 Ok(if path.is_dir() {
40 let mut last_modified = None; 40 let mut last_modified = Some(String::new());
41 let mut last_modified_timestamp = 0;
42
41 let mut children: Vec<PathInfo> = Vec::new(); 43 let mut children: Vec<PathInfo> = Vec::new();
42 44
43 let paths = std::fs::read_dir(path).unwrap(); 45 let paths = std::fs::read_dir(path).unwrap();
@@ -48,11 +50,17 @@ impl PathInfo {
48 panic!("HUH"); 50 panic!("HUH");
49 }; 51 };
50 let handle = Self::handle_dir(config, rl.1, location_root)?; 52 let handle = Self::handle_dir(config, rl.1, location_root)?;
51 if handle.last_modified.is_some() { 53 if let Some(lm) = handle.last_modified.clone() {
52 // FIX: Check if new last modified is newer than old one 54 if last_modified != None {
53 last_modified = handle.last_modified.clone(); 55 let ts = Backup::from_index(config, &lm)?.timestamp;
56 if ts > last_modified_timestamp {
57 last_modified_timestamp = ts;
58 last_modified = Some(lm);
59 };
60 }
61 } else {
62 last_modified = None;
54 }; 63 };
55 last_modified = None;
56 children.push(handle); 64 children.push(handle);
57 } 65 }
58 Self { 66 Self {
@@ -103,7 +111,7 @@ impl PathInfo {
103 return Ok(None); 111 return Ok(None);
104 }; 112 };
105 113
106 let modified_backup = if let Some(modified_backup_id) = last_file.last_modified.clone() { 114 let modified_backup = if let Some(modified_backup_id) = &last_file.last_modified {
107 Backup::from_index(config, modified_backup_id)? 115 Backup::from_index(config, modified_backup_id)?
108 } else { 116 } else {
109 last_backup 117 last_backup