From 97896023cf5b8ac9a58baaba7d0571b0cc9ff8f7 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sun, 8 Sep 2024 23:59:39 +0200 Subject: add logging --- src/backup.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/backup.rs') diff --git a/src/backup.rs b/src/backup.rs index 675f020..e463593 100644 --- a/src/backup.rs +++ b/src/backup.rs @@ -6,6 +6,7 @@ use std::{ }; use serde::{Deserialize, Serialize}; +use tracing::info; use uuid::Uuid; use crate::{ @@ -15,7 +16,7 @@ use crate::{ pathinfo::PathInfo, }; -pub type BackupId = String; +pub type Id = String; #[derive(Debug, Serialize, Deserialize)] pub struct Backup { @@ -43,13 +44,12 @@ impl Backup { } pub fn save(&self, config: &Config) -> Result<()> { - println!("Save Backup {:?}", self.get_location(config)); - // println!("{self:#?}"); + info!("Save Backup {:?}", self.get_location(config)); self.get_location(config).append_to_root(config)?; let backup_root = self.get_location(config).get_absolute_dir(config); create_dir_all(&backup_root).unwrap(); - let path = format!("{}/index.json", backup_root); + let path = format!("{backup_root}/index.json"); let mut f = File::create(path).unwrap(); f.write_all(&serde_json::to_vec(self).unwrap()).unwrap(); @@ -62,7 +62,7 @@ impl Backup { pub fn get_last(config: &Config) -> Result> { let backup_index_root = format!("{}/index.json", config.root); - let list: Vec = match Self::get_json_content(&backup_index_root) { + let list: Vec = match Self::get_json_content(&backup_index_root) { Ok(list) => list, Err(err) => { if err.to_string() == "io: No such file or directory (os error 2)" { @@ -78,9 +78,9 @@ impl Backup { )?)) } - pub fn from_index(config: &Config, id: &BackupId) -> Result { + pub fn from_index(config: &Config, id: &Id) -> Result { let backup_index_root = format!("{}/index.json", config.root); - let list: Vec = Self::get_json_content(&backup_index_root)?; + let list: Vec = Self::get_json_content(&backup_index_root)?; let index_loc = list .iter() .find(|bl| &bl.id == id) @@ -94,10 +94,10 @@ impl Backup { Ok(index_file) } - pub fn get_location(&self, config: &Config) -> BackupLocation { + pub fn get_location(&self, config: &Config) -> IndexEntry { let rel_location = format!("{}_{}", config.device, self.timestamp); - BackupLocation { + IndexEntry { id: self.id.to_string(), rel_location, } @@ -106,7 +106,7 @@ impl Backup { pub fn get_absolute_file_location(&self, config: &Config, rel_location: &str) -> String { let loc = self.get_location(config).get_absolute_dir(config); - format!("{}/{}", loc, rel_location) + format!("{loc}/{rel_location}") } fn get_json_content Deserialize<'a>>(path: &str) -> Result { @@ -125,12 +125,12 @@ impl Backup { } #[derive(Debug, Clone, Serialize, Deserialize)] -pub struct BackupLocation { - id: BackupId, +pub struct IndexEntry { + id: Id, rel_location: String, } -impl BackupLocation { +impl IndexEntry { pub fn get_absolute_dir(&self, config: &Config) -> String { format!("{}/{}", config.root, self.rel_location) } @@ -142,7 +142,7 @@ impl BackupLocation { let mut f = File::open(&path)?; let mut content = String::new(); f.read_to_string(&mut content)?; - let mut loc: Vec = serde_json::from_str(&content)?; + let mut loc: Vec = serde_json::from_str(&content)?; let mut f = File::create(path)?; loc.push(self.clone()); -- cgit v1.2.3