From 97896023cf5b8ac9a58baaba7d0571b0cc9ff8f7 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sun, 8 Sep 2024 23:59:39 +0200 Subject: add logging --- src/pathinfo.rs | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'src/pathinfo.rs') 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::{ }; use serde::{Deserialize, Serialize}; +use tracing::info; use crate::{ - backup::{Backup, BackupId}, + backup::{Backup, Id}, config::Config, error::{Error, Result}, }; @@ -18,7 +19,7 @@ pub struct PathInfo { is_file: bool, rel_location: String, location_root: LocationRoot, - last_modified: Option, + last_modified: Option, children: Vec, } @@ -34,7 +35,7 @@ impl PathInfo { rel_location: &str, location_root: &LocationRoot, ) -> Result { - println!("Handling {rel_location}"); + info!("Handling {rel_location}"); let path = Self::get_abs_path(&location_root.to_string(), rel_location); Ok(if path.is_dir() { let mut last_modified = Some(String::new()); @@ -51,7 +52,7 @@ impl PathInfo { }; let handle = Self::handle_dir(config, rl.1, location_root)?; if let Some(lm) = handle.last_modified.clone() { - if last_modified != None { + if last_modified.is_some() { let ts = Backup::from_index(config, &lm)?.timestamp; if ts > last_modified_timestamp { last_modified_timestamp = ts; @@ -82,7 +83,7 @@ impl PathInfo { ) -> Result { let last_modified = Self::compare_to_last_modified(config, location_root, rel_location)?; - println!("From file {rel_location} ({:?})", last_modified); + info!("From file {rel_location} ({last_modified:?})"); Ok(Self { rel_location: rel_location.to_string(), @@ -107,7 +108,6 @@ impl PathInfo { 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"); return Ok(None); }; @@ -120,8 +120,7 @@ impl PathInfo { let old_path = modified_backup.get_absolute_file_location(config, &last_file.rel_location); let new_path = format!("{location_root}/{rel_location}"); - let mut old = File::open(old_path)?; - let mut new = File::open(new_path)?; + let mut old = File::open(old_path)?; let mut new = File::open(new_path)?; let old_len = old.metadata()?.len(); let new_len = new.metadata()?.len(); @@ -147,15 +146,10 @@ impl PathInfo { ) -> 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() { @@ -174,11 +168,9 @@ impl PathInfo { if self.last_modified.is_some() { return Ok(()); } - println!("Save File {:?}", self.rel_location); + info!("Save File {:?}", self.rel_location); 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()); let np = Path::new(&new_path); if let Some(parent) = np.parent() { create_dir_all(parent)?; @@ -194,7 +186,7 @@ impl PathInfo { } fn get_abs_path(location_root: &str, rel_location: &str) -> PathBuf { - let path = format!("{}/{}", location_root, rel_location); + let path = format!("{location_root}/{rel_location}"); PathBuf::from(path) } @@ -383,7 +375,7 @@ mod tests { config.root = "./backup-test".to_string(); config .directories - .push("u:fx/code/proj/fxbaup/backup-test-dir".to_string()); + .push("u:fx/code/proj/arps/backup-test-dir".to_string()); create_dir_all("./backup-test-dir")?; let mut f = File::create("./backup-test-dir/size.txt")?; @@ -403,12 +395,12 @@ mod tests { let mut f = File::create("./backup-test-dir/content.txt")?; f.write_all("unmodefied".as_bytes())?; - let pi = PathInfo::from_path(&config, "u:fx/code/proj/fxbaup/backup-test-dir")?; + let pi = PathInfo::from_path(&config, "u:fx/code/proj/arps/backup-test-dir")?; let last_backup = Backup::get_last(&config)?.unwrap(); for file in pi.children { println!("test rel: {}", file.rel_location); - let res = if file.rel_location == "code/proj/fxbaup/backup-test-dir/nothing.txt" { + let res = if file.rel_location == "code/proj/arps/backup-test-dir/nothing.txt" { Some(last_backup.id.clone()) } else { None -- cgit v1.2.3