From 4b9514f364f1711555208bd4b9316e7d5c597dc5 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sun, 8 Sep 2024 18:54:41 +0200 Subject: fixed last modified --- src/pathinfo.rs | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'src/pathinfo.rs') diff --git a/src/pathinfo.rs b/src/pathinfo.rs index 641e7ef..3e4b5c2 100644 --- a/src/pathinfo.rs +++ b/src/pathinfo.rs @@ -52,6 +52,7 @@ impl PathInfo { // FIX: Check if new last modified is newer than old one last_modified = handle.last_modified.clone(); }; + last_modified = None; children.push(handle); } Self { @@ -94,10 +95,8 @@ impl PathInfo { return Ok(None); }; - let files = last_backup.files.clone(); - let last_file_opt = files.iter().find(|file| file.rel_location == rel_location && file.location_root == *location_root); - + let last_file_opt = Self::find_last_modified(files, rel_location, location_root); let Some(last_file) = last_file_opt else { // File didn't exist last Backup println!("File didn't exist last Backup"); @@ -133,6 +132,32 @@ impl PathInfo { Ok(Some(modified_backup.id.clone())) } + pub fn find_last_modified( + files: Vec, + rel_location: &str, + location_root: &LocationRoot, + ) -> Option { + for path in files { + if path.is_file { + println!("Checking {}", path.rel_location); + println!("File rel: {} ?= {}", path.rel_location, rel_location); + println!("File rot: {} ?= {}", path.location_root, location_root); + if path.rel_location == rel_location && path.location_root == *location_root { + println!("Return Some"); + return Some(path); + }; + } else { + println!("Checking all in {path:?}"); + let is_modified = + PathInfo::find_last_modified(path.children, rel_location, location_root); + if is_modified.is_some() { + return is_modified; + }; + } + } + None + } + pub fn get_absolute_path(&self) -> PathBuf { Self::get_abs_path(&self.location_root.to_string(), &self.rel_location) } @@ -142,11 +167,7 @@ impl PathInfo { return Ok(()); } println!("Save File {:?}", self.rel_location); - if !self.is_file { - for child in &self.children { - child.save(backup_root)?; - } - } else { + if self.is_file { let new_path = format!("{}/{}", backup_root, self.rel_location); // println!("New Path: {new_path}"); // println!("Old Path: {:?}", self.get_absolute_path()); @@ -155,6 +176,10 @@ impl PathInfo { create_dir_all(parent)?; } std::fs::copy(self.get_absolute_path(), new_path)?; + } else { + for child in &self.children { + child.save(backup_root)?; + } }; Ok(()) -- cgit v1.2.3