From 9a34651063029394845a3e18fe7afd5b7c4db777 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sun, 8 Sep 2024 22:30:05 +0200 Subject: folder last modified reflects newest child --- src/backup.rs | 8 ++++---- src/pathinfo.rs | 24 ++++++++++++++++-------- 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; #[derive(Debug, Serialize, Deserialize)] pub struct Backup { pub id: String, - timestamp: u64, + pub timestamp: u64, packages: Vec, pub files: Vec, device: String, @@ -74,16 +74,16 @@ impl Backup { Ok(Some(Self::from_index( config, - list.last().ok_or(Error::BackupNotFound)?.id.clone(), + &list.last().ok_or(Error::BackupNotFound)?.id, )?)) } - pub fn from_index(config: &Config, id: BackupId) -> Result { + pub fn from_index(config: &Config, id: &BackupId) -> Result { let backup_index_root = format!("{}/index.json", config.root); let list: Vec = Self::get_json_content(&backup_index_root)?; let index_loc = list .iter() - .find(|bl| bl.id == id) + .find(|bl| &bl.id == id) .ok_or(Error::BackupNotFound)? .rel_location .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::{ #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PathInfo { - pub is_file: bool, + is_file: bool, rel_location: String, location_root: LocationRoot, last_modified: Option, - pub children: Vec, + children: Vec, } impl PathInfo { @@ -37,7 +37,9 @@ impl PathInfo { println!("Handling {rel_location}"); let path = Self::get_abs_path(&location_root.to_string(), rel_location); Ok(if path.is_dir() { - let mut last_modified = None; + let mut last_modified = Some(String::new()); + let mut last_modified_timestamp = 0; + let mut children: Vec = Vec::new(); let paths = std::fs::read_dir(path).unwrap(); @@ -48,11 +50,17 @@ impl PathInfo { panic!("HUH"); }; let handle = Self::handle_dir(config, rl.1, location_root)?; - if handle.last_modified.is_some() { - // FIX: Check if new last modified is newer than old one - last_modified = handle.last_modified.clone(); + if let Some(lm) = handle.last_modified.clone() { + if last_modified != None { + let ts = Backup::from_index(config, &lm)?.timestamp; + if ts > last_modified_timestamp { + last_modified_timestamp = ts; + last_modified = Some(lm); + }; + } + } else { + last_modified = None; }; - last_modified = None; children.push(handle); } Self { @@ -103,7 +111,7 @@ impl PathInfo { return Ok(None); }; - let modified_backup = if let Some(modified_backup_id) = last_file.last_modified.clone() { + let modified_backup = if let Some(modified_backup_id) = &last_file.last_modified { Backup::from_index(config, modified_backup_id)? } else { last_backup -- cgit v1.2.3