From 97896023cf5b8ac9a58baaba7d0571b0cc9ff8f7 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sun, 8 Sep 2024 23:59:39 +0200 Subject: add logging --- .gitignore | 1 + Cargo.lock | 254 +++++++++++++++++++++++++++++++++++++++++++++--- Cargo.toml | 5 +- src/backup.rs | 28 +++--- src/config.rs | 7 +- src/main.rs | 47 +++++---- src/packages.rs | 2 +- src/packages/pacman.rs | 18 +++- src/packages/portage.rs | 5 +- src/pathinfo.rs | 32 +++--- 10 files changed, 324 insertions(+), 75 deletions(-) diff --git a/.gitignore b/.gitignore index 57e4770..a2956f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target /backup* tags +*.log diff --git a/Cargo.lock b/Cargo.lock index 09c9843..e72016e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,12 +17,39 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "anyhow" version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "arps" +version = "0.1.0" +dependencies = [ + "anyhow", + "color-eyre", + "config", + "gethostname", + "serde", + "serde_json", + "thiserror", + "toml", + "tracing", + "tracing-appender", + "tracing-subscriber", + "uuid", +] + [[package]] name = "async-trait" version = "0.1.82" @@ -173,6 +200,21 @@ dependencies = [ "libc", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + [[package]] name = "crunchy" version = "0.2.2" @@ -189,6 +231,15 @@ dependencies = [ "typenum", ] +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", +] + [[package]] name = "digest" version = "0.10.7" @@ -234,21 +285,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "fxbaup" -version = "0.1.0" -dependencies = [ - "anyhow", - "color-eyre", - "config", - "gethostname", - "serde", - "serde_json", - "thiserror", - "toml", - "uuid", -] - [[package]] name = "generic-array" version = "0.14.7" @@ -355,6 +391,21 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata 0.1.10", +] + [[package]] name = "memchr" version = "2.7.4" @@ -386,6 +437,22 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + +[[package]] +name = "num-conv" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" + [[package]] name = "object" version = "0.32.2" @@ -411,6 +478,12 @@ dependencies = [ "hashbrown 0.13.2", ] +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "owo-colors" version = "3.5.0" @@ -474,6 +547,12 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +[[package]] +name = "powerfmt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + [[package]] name = "proc-macro2" version = "1.0.86" @@ -492,6 +571,50 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "regex" +version = "1.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.4.7", + "regex-syntax 0.8.4", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.4", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + [[package]] name = "ron" version = "0.8.1" @@ -606,6 +729,12 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + [[package]] name = "syn" version = "2.0.77" @@ -647,6 +776,37 @@ dependencies = [ "once_cell", ] +[[package]] +name = "time" +version = "0.3.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" +dependencies = [ + "deranged", + "itoa", + "num-conv", + "powerfmt", + "serde", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" + +[[package]] +name = "time-macros" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" +dependencies = [ + "num-conv", + "time-core", +] + [[package]] name = "tiny-keccak" version = "2.0.2" @@ -697,9 +857,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-appender" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3566e8ce28cc0a3fe42519fc80e6b4c943cc4c8cef275620eb8dac2d3d4e06cf" +dependencies = [ + "crossbeam-channel", + "thiserror", + "time", + "tracing-subscriber", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tracing-core" version = "0.1.32" @@ -720,15 +904,33 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + [[package]] name = "tracing-subscriber" version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", "sharded-slab", + "smallvec", "thread_local", + "tracing", "tracing-core", + "tracing-log", ] [[package]] @@ -782,6 +984,28 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-sys" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index 62a91a7..9fc7b01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "fxbaup" +name = "arps" version = "0.1.0" edition = "2021" @@ -12,4 +12,7 @@ serde = { version = "1.0.209", features = ["derive"] } serde_json = "1.0.128" thiserror = "1.0.63" toml = "0.8.19" +tracing = "0.1.40" +tracing-appender = "0.2.3" +tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } uuid = { version = "1.10.0", features = ["v4"] } 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()); diff --git a/src/config.rs b/src/config.rs index 439c17c..13dd0e4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,6 @@ use config::{File, Map}; use serde::{Deserialize, Serialize}; +use tracing::{debug, trace}; #[derive(Debug, Serialize, Deserialize)] #[serde(default)] @@ -27,11 +28,15 @@ impl Default for Config { impl Config { pub fn load() -> Result { + debug!("load config"); let config = config::Config::builder() .add_source(File::with_name("config.toml").required(false)) .add_source(config::Environment::with_prefix("FXBAUP").separator("_")) .build()?; - config.try_deserialize() + let cfg = config.try_deserialize(); + trace!(?cfg, "loaded config"); + + cfg } } diff --git a/src/main.rs b/src/main.rs index e67e535..1284e0c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,8 @@ use backup::Backup; use config::Config; use packages::{pacman::Pacman, PackageManager}; +use tracing::{debug, info, level_filters::LevelFilter}; +use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; mod backup; mod config; @@ -11,30 +13,39 @@ mod pathinfo; fn main() -> color_eyre::Result<()> { color_eyre::install()?; + let file_appender = tracing_appender::rolling::never("./", "arps.log"); + let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender); + + tracing_subscriber::registry() + .with( + fmt::layer() + .with_writer(non_blocking) + .with_file(false) + .with_ansi(false) + .without_time(), + ) + .with(fmt::layer().with_file(false).without_time()) + .with( + EnvFilter::builder() + .with_default_directive(LevelFilter::INFO.into()) + .from_env_lossy(), + ) + .init(); + debug!("logging initialized"); + let mut cfg = Config::load()?; cfg.user.push("fx".to_string()); cfg.directories.push("~/.config/nvim".to_string()); - // cfg.directories.push("~/.config/hypr".to_string()); cfg.root = "./backup".to_string(); - // cfg.root = "./backup-test".to_string(); - // cfg.directories.push("u:/code/proj/fxbaup/backup-test-dir".to_string()); let pacman = Pacman; let pkgs = pacman.get_installed()?; - - let backup = Backup::create(&cfg, pkgs)?; - // println!("{backup:#?}"); - - backup.save(&cfg)?; - - // PathInfo::compare_to_last_modified(&cfg, &LocationRoot::User("fx".to_string()), "code/proj/fxbaub/backup-test-dir/size.txt")?; - // PathInfo::compare_to_last_modified(&cfg, &LocationRoot::User("fx".to_string()), "code/proj/fxbaub/backup-test-dir/content.txt")?; - - // let index = Backup::get_index(&cfg, None)?; - - // println!("{index:#?}"); - - // let fi = FileInfo::new("~/.config/nvim", &cfg)?; - // println!("{:?}", fi.get_absolute_path()); + let backup = Backup::create(&cfg, pkgs); + // info!(?backup); + // pacman.install(vec![Package { + // id: "lapce".to_string(), + // version: "0.4.2-1".to_string(), + // explicit: true, + // }])?; Ok(()) } diff --git a/src/packages.rs b/src/packages.rs index e7b4c3d..5ee5664 100644 --- a/src/packages.rs +++ b/src/packages.rs @@ -15,5 +15,5 @@ pub struct Package { pub trait PackageManager { fn get_installed(&self) -> Result>; - fn install(&self, pkgs: Vec); + fn install(&self, pkgs: Vec) -> Result<()>; } diff --git a/src/packages/pacman.rs b/src/packages/pacman.rs index b5be4c0..e10c6fb 100644 --- a/src/packages/pacman.rs +++ b/src/packages/pacman.rs @@ -1,4 +1,4 @@ -use std::process::Command; +use std::process::{Command, Stdio}; use super::{Package, PackageManager}; @@ -34,13 +34,23 @@ impl PackageManager for Pacman { id: split[0].to_string(), version: split[1].to_string(), explicit, - }) + }); } Ok(pkgs) } - fn install(&self, _pkgs: Vec) { - todo!(); + fn install(&self, pkgs: Vec) -> Result<()> { + let mut args = vec!["--noconfirm".to_string(), "-S".to_string()]; + + for pkg in pkgs { + args.push(pkg.id); + } + Command::new("pacman") + .stdout(Stdio::inherit()) + .args(args) + .spawn()? + .wait_with_output()?; + Ok(()) } } diff --git a/src/packages/portage.rs b/src/packages/portage.rs index 6b9e508..f9a760b 100644 --- a/src/packages/portage.rs +++ b/src/packages/portage.rs @@ -1,3 +1,5 @@ +use tracing::error; + use super::PackageManager; pub struct Portage; @@ -7,7 +9,8 @@ impl PackageManager for Portage { todo!() } - fn install(&self, pkgs: Vec) { + fn install(&self, pkgs: Vec) -> crate::error::Result<()> { + error!("Install {pkgs:?}"); todo!() } } 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