diff options
Diffstat (limited to 'src/pathinfo.rs')
-rw-r--r-- | src/pathinfo.rs | 41 |
1 files changed, 33 insertions, 8 deletions
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 { | |||
52 | // FIX: Check if new last modified is newer than old one | 52 | // FIX: Check if new last modified is newer than old one |
53 | last_modified = handle.last_modified.clone(); | 53 | last_modified = handle.last_modified.clone(); |
54 | }; | 54 | }; |
55 | last_modified = None; | ||
55 | children.push(handle); | 56 | children.push(handle); |
56 | } | 57 | } |
57 | Self { | 58 | Self { |
@@ -94,10 +95,8 @@ impl PathInfo { | |||
94 | return Ok(None); | 95 | return Ok(None); |
95 | }; | 96 | }; |
96 | 97 | ||
97 | |||
98 | let files = last_backup.files.clone(); | 98 | let files = last_backup.files.clone(); |
99 | let last_file_opt = files.iter().find(|file| file.rel_location == rel_location && file.location_root == *location_root); | 99 | let last_file_opt = Self::find_last_modified(files, rel_location, location_root); |
100 | |||
101 | let Some(last_file) = last_file_opt else { | 100 | let Some(last_file) = last_file_opt else { |
102 | // File didn't exist last Backup | 101 | // File didn't exist last Backup |
103 | println!("File didn't exist last Backup"); | 102 | println!("File didn't exist last Backup"); |
@@ -133,6 +132,32 @@ impl PathInfo { | |||
133 | Ok(Some(modified_backup.id.clone())) | 132 | Ok(Some(modified_backup.id.clone())) |
134 | } | 133 | } |
135 | 134 | ||
135 | pub fn find_last_modified( | ||
136 | files: Vec<Self>, | ||
137 | rel_location: &str, | ||
138 | location_root: &LocationRoot, | ||
139 | ) -> Option<PathInfo> { | ||
140 | for path in files { | ||
141 | if path.is_file { | ||
142 | println!("Checking {}", path.rel_location); | ||
143 | println!("File rel: {} ?= {}", path.rel_location, rel_location); | ||
144 | println!("File rot: {} ?= {}", path.location_root, location_root); | ||
145 | if path.rel_location == rel_location && path.location_root == *location_root { | ||
146 | println!("Return Some"); | ||
147 | return Some(path); | ||
148 | }; | ||
149 | } else { | ||
150 | println!("Checking all in {path:?}"); | ||
151 | let is_modified = | ||
152 | PathInfo::find_last_modified(path.children, rel_location, location_root); | ||
153 | if is_modified.is_some() { | ||
154 | return is_modified; | ||
155 | }; | ||
156 | } | ||
157 | } | ||
158 | None | ||
159 | } | ||
160 | |||
136 | pub fn get_absolute_path(&self) -> PathBuf { | 161 | pub fn get_absolute_path(&self) -> PathBuf { |
137 | Self::get_abs_path(&self.location_root.to_string(), &self.rel_location) | 162 | Self::get_abs_path(&self.location_root.to_string(), &self.rel_location) |
138 | } | 163 | } |
@@ -142,11 +167,7 @@ impl PathInfo { | |||
142 | return Ok(()); | 167 | return Ok(()); |
143 | } | 168 | } |
144 | println!("Save File {:?}", self.rel_location); | 169 | println!("Save File {:?}", self.rel_location); |
145 | if !self.is_file { | 170 | if self.is_file { |
146 | for child in &self.children { | ||
147 | child.save(backup_root)?; | ||
148 | } | ||
149 | } else { | ||
150 | let new_path = format!("{}/{}", backup_root, self.rel_location); | 171 | let new_path = format!("{}/{}", backup_root, self.rel_location); |
151 | // println!("New Path: {new_path}"); | 172 | // println!("New Path: {new_path}"); |
152 | // println!("Old Path: {:?}", self.get_absolute_path()); | 173 | // println!("Old Path: {:?}", self.get_absolute_path()); |
@@ -155,6 +176,10 @@ impl PathInfo { | |||
155 | create_dir_all(parent)?; | 176 | create_dir_all(parent)?; |
156 | } | 177 | } |
157 | std::fs::copy(self.get_absolute_path(), new_path)?; | 178 | std::fs::copy(self.get_absolute_path(), new_path)?; |
179 | } else { | ||
180 | for child in &self.children { | ||
181 | child.save(backup_root)?; | ||
182 | } | ||
158 | }; | 183 | }; |
159 | 184 | ||
160 | Ok(()) | 185 | Ok(()) |