summaryrefslogtreecommitdiff
path: root/src/pathinfo.rs
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2024-09-08 23:59:39 +0200
committerfxqnlr <[email protected]>2024-09-08 23:59:39 +0200
commit97896023cf5b8ac9a58baaba7d0571b0cc9ff8f7 (patch)
tree5a7840bb1905bd84ba95cca11b74762fd028f3d0 /src/pathinfo.rs
parent9a34651063029394845a3e18fe7afd5b7c4db777 (diff)
downloadarbs-97896023cf5b8ac9a58baaba7d0571b0cc9ff8f7.tar
arbs-97896023cf5b8ac9a58baaba7d0571b0cc9ff8f7.tar.gz
arbs-97896023cf5b8ac9a58baaba7d0571b0cc9ff8f7.zip
add logging
Diffstat (limited to 'src/pathinfo.rs')
-rw-r--r--src/pathinfo.rs32
1 files changed, 12 insertions, 20 deletions
diff --git a/src/pathinfo.rs b/src/pathinfo.rs
index 212dd2a..5b9aa21 100644
--- a/src/pathinfo.rs
+++ b/src/pathinfo.rs
@@ -6,9 +6,10 @@ use std::{
6}; 6};
7 7
8use serde::{Deserialize, Serialize}; 8use serde::{Deserialize, Serialize};
9use tracing::info;
9 10
10use crate::{ 11use crate::{
11 backup::{Backup, BackupId}, 12 backup::{Backup, Id},
12 config::Config, 13 config::Config,
13 error::{Error, Result}, 14 error::{Error, Result},
14}; 15};
@@ -18,7 +19,7 @@ pub struct PathInfo {
18 is_file: bool, 19 is_file: bool,
19 rel_location: String, 20 rel_location: String,
20 location_root: LocationRoot, 21 location_root: LocationRoot,
21 last_modified: Option<BackupId>, 22 last_modified: Option<Id>,
22 children: Vec<PathInfo>, 23 children: Vec<PathInfo>,
23} 24}
24 25
@@ -34,7 +35,7 @@ impl PathInfo {
34 rel_location: &str, 35 rel_location: &str,
35 location_root: &LocationRoot, 36 location_root: &LocationRoot,
36 ) -> Result<Self> { 37 ) -> Result<Self> {
37 println!("Handling {rel_location}"); 38 info!("Handling {rel_location}");
38 let path = Self::get_abs_path(&location_root.to_string(), rel_location); 39 let path = Self::get_abs_path(&location_root.to_string(), rel_location);
39 Ok(if path.is_dir() { 40 Ok(if path.is_dir() {
40 let mut last_modified = Some(String::new()); 41 let mut last_modified = Some(String::new());
@@ -51,7 +52,7 @@ impl PathInfo {
51 }; 52 };
52 let handle = Self::handle_dir(config, rl.1, location_root)?; 53 let handle = Self::handle_dir(config, rl.1, location_root)?;
53 if let Some(lm) = handle.last_modified.clone() { 54 if let Some(lm) = handle.last_modified.clone() {
54 if last_modified != None { 55 if last_modified.is_some() {
55 let ts = Backup::from_index(config, &lm)?.timestamp; 56 let ts = Backup::from_index(config, &lm)?.timestamp;
56 if ts > last_modified_timestamp { 57 if ts > last_modified_timestamp {
57 last_modified_timestamp = ts; 58 last_modified_timestamp = ts;
@@ -82,7 +83,7 @@ impl PathInfo {
82 ) -> Result<Self> { 83 ) -> Result<Self> {
83 let last_modified = Self::compare_to_last_modified(config, location_root, rel_location)?; 84 let last_modified = Self::compare_to_last_modified(config, location_root, rel_location)?;
84 85
85 println!("From file {rel_location} ({:?})", last_modified); 86 info!("From file {rel_location} ({last_modified:?})");
86 87
87 Ok(Self { 88 Ok(Self {
88 rel_location: rel_location.to_string(), 89 rel_location: rel_location.to_string(),
@@ -107,7 +108,6 @@ impl PathInfo {
107 let last_file_opt = Self::find_last_modified(files, rel_location, location_root); 108 let last_file_opt = Self::find_last_modified(files, rel_location, location_root);
108 let Some(last_file) = last_file_opt else { 109 let Some(last_file) = last_file_opt else {
109 // File didn't exist last Backup 110 // File didn't exist last Backup
110 println!("File didn't exist last Backup");
111 return Ok(None); 111 return Ok(None);
112 }; 112 };
113 113
@@ -120,8 +120,7 @@ impl PathInfo {
120 let old_path = modified_backup.get_absolute_file_location(config, &last_file.rel_location); 120 let old_path = modified_backup.get_absolute_file_location(config, &last_file.rel_location);
121 let new_path = format!("{location_root}/{rel_location}"); 121 let new_path = format!("{location_root}/{rel_location}");
122 122
123 let mut old = File::open(old_path)?; 123 let mut old = File::open(old_path)?; let mut new = File::open(new_path)?;
124 let mut new = File::open(new_path)?;
125 124
126 let old_len = old.metadata()?.len(); 125 let old_len = old.metadata()?.len();
127 let new_len = new.metadata()?.len(); 126 let new_len = new.metadata()?.len();
@@ -147,15 +146,10 @@ impl PathInfo {
147 ) -> Option<PathInfo> { 146 ) -> Option<PathInfo> {
148 for path in files { 147 for path in files {
149 if path.is_file { 148 if path.is_file {
150 println!("Checking {}", path.rel_location);
151 println!("File rel: {} ?= {}", path.rel_location, rel_location);
152 println!("File rot: {} ?= {}", path.location_root, location_root);
153 if path.rel_location == rel_location && path.location_root == *location_root { 149 if path.rel_location == rel_location && path.location_root == *location_root {
154 println!("Return Some");
155 return Some(path); 150 return Some(path);
156 }; 151 };
157 } else { 152 } else {
158 println!("Checking all in {path:?}");
159 let is_modified = 153 let is_modified =
160 PathInfo::find_last_modified(path.children, rel_location, location_root); 154 PathInfo::find_last_modified(path.children, rel_location, location_root);
161 if is_modified.is_some() { 155 if is_modified.is_some() {
@@ -174,11 +168,9 @@ impl PathInfo {
174 if self.last_modified.is_some() { 168 if self.last_modified.is_some() {
175 return Ok(()); 169 return Ok(());
176 } 170 }
177 println!("Save File {:?}", self.rel_location); 171 info!("Save File {:?}", self.rel_location);
178 if self.is_file { 172 if self.is_file {
179 let new_path = format!("{}/{}", backup_root, self.rel_location); 173 let new_path = format!("{}/{}", backup_root, self.rel_location);
180 // println!("New Path: {new_path}");
181 // println!("Old Path: {:?}", self.get_absolute_path());
182 let np = Path::new(&new_path); 174 let np = Path::new(&new_path);
183 if let Some(parent) = np.parent() { 175 if let Some(parent) = np.parent() {
184 create_dir_all(parent)?; 176 create_dir_all(parent)?;
@@ -194,7 +186,7 @@ impl PathInfo {
194 } 186 }
195 187
196 fn get_abs_path(location_root: &str, rel_location: &str) -> PathBuf { 188 fn get_abs_path(location_root: &str, rel_location: &str) -> PathBuf {
197 let path = format!("{}/{}", location_root, rel_location); 189 let path = format!("{location_root}/{rel_location}");
198 PathBuf::from(path) 190 PathBuf::from(path)
199 } 191 }
200 192
@@ -383,7 +375,7 @@ mod tests {
383 config.root = "./backup-test".to_string(); 375 config.root = "./backup-test".to_string();
384 config 376 config
385 .directories 377 .directories
386 .push("u:fx/code/proj/fxbaup/backup-test-dir".to_string()); 378 .push("u:fx/code/proj/arps/backup-test-dir".to_string());
387 379
388 create_dir_all("./backup-test-dir")?; 380 create_dir_all("./backup-test-dir")?;
389 let mut f = File::create("./backup-test-dir/size.txt")?; 381 let mut f = File::create("./backup-test-dir/size.txt")?;
@@ -403,12 +395,12 @@ mod tests {
403 let mut f = File::create("./backup-test-dir/content.txt")?; 395 let mut f = File::create("./backup-test-dir/content.txt")?;
404 f.write_all("unmodefied".as_bytes())?; 396 f.write_all("unmodefied".as_bytes())?;
405 397
406 let pi = PathInfo::from_path(&config, "u:fx/code/proj/fxbaup/backup-test-dir")?; 398 let pi = PathInfo::from_path(&config, "u:fx/code/proj/arps/backup-test-dir")?;
407 399
408 let last_backup = Backup::get_last(&config)?.unwrap(); 400 let last_backup = Backup::get_last(&config)?.unwrap();
409 for file in pi.children { 401 for file in pi.children {
410 println!("test rel: {}", file.rel_location); 402 println!("test rel: {}", file.rel_location);
411 let res = if file.rel_location == "code/proj/fxbaup/backup-test-dir/nothing.txt" { 403 let res = if file.rel_location == "code/proj/arps/backup-test-dir/nothing.txt" {
412 Some(last_backup.id.clone()) 404 Some(last_backup.id.clone())
413 } else { 405 } else {
414 None 406 None