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/pathinfo.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/pathinfo.rs') 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