diff options
author | fxqnlr <[email protected]> | 2024-09-25 15:13:34 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2024-09-25 15:13:34 +0200 |
commit | d44041040d755306c39d6de8da5b42d7ded6808c (patch) | |
tree | d664c15e014aa36dc5735ec4be4919866fb6a9e5 /src/pathinfo.rs | |
parent | 0ed94b3f011a2d3c22bdc4affb502720be22c371 (diff) | |
download | arbs-d44041040d755306c39d6de8da5b42d7ded6808c.tar arbs-d44041040d755306c39d6de8da5b42d7ded6808c.tar.gz arbs-d44041040d755306c39d6de8da5b42d7ded6808c.zip |
added notifications and improved stuff
Diffstat (limited to 'src/pathinfo.rs')
-rw-r--r-- | src/pathinfo.rs | 110 |
1 files changed, 56 insertions, 54 deletions
diff --git a/src/pathinfo.rs b/src/pathinfo.rs index 1231ff8..009f46a 100644 --- a/src/pathinfo.rs +++ b/src/pathinfo.rs | |||
@@ -6,7 +6,7 @@ use std::{ | |||
6 | }; | 6 | }; |
7 | 7 | ||
8 | use serde::{Deserialize, Serialize}; | 8 | use serde::{Deserialize, Serialize}; |
9 | use tracing::{debug, info}; | 9 | use tracing::{debug, info, trace}; |
10 | 10 | ||
11 | use crate::{ | 11 | use crate::{ |
12 | backup::{Backup, Id}, | 12 | backup::{Backup, Id}, |
@@ -35,7 +35,7 @@ impl PathInfo { | |||
35 | rel_location: &str, | 35 | rel_location: &str, |
36 | location_root: &LocationRoot, | 36 | location_root: &LocationRoot, |
37 | ) -> Result<Self> { | 37 | ) -> Result<Self> { |
38 | info!("Handling {rel_location}"); | 38 | trace!("Handling {rel_location}"); |
39 | 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); |
40 | Ok(if path.is_dir() { | 40 | Ok(if path.is_dir() { |
41 | let mut last_modified = Some(String::new()); | 41 | let mut last_modified = Some(String::new()); |
@@ -83,7 +83,7 @@ impl PathInfo { | |||
83 | ) -> Result<Self> { | 83 | ) -> Result<Self> { |
84 | 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)?; |
85 | 85 | ||
86 | info!("From file {rel_location} ({last_modified:?})"); | 86 | debug!("From file {rel_location} ({last_modified:?})"); |
87 | 87 | ||
88 | Ok(Self { | 88 | Ok(Self { |
89 | rel_location: rel_location.to_string(), | 89 | rel_location: rel_location.to_string(), |
@@ -301,14 +301,15 @@ mod tests { | |||
301 | .custom_directories | 301 | .custom_directories |
302 | .insert("test".to_string(), "/usr/local/test".to_string()); | 302 | .insert("test".to_string(), "/usr/local/test".to_string()); |
303 | 303 | ||
304 | let mut values_ok: Vec<(&str, LocationRoot)> = Vec::new(); | 304 | let values_ok = vec![ |
305 | values_ok.push(("u:test", LocationRoot::User)); | 305 | ("u:test", LocationRoot::User), |
306 | values_ok.push(("s:", LocationRoot::SystemConfig)); | 306 | ("s:", LocationRoot::SystemConfig), |
307 | values_ok.push(("r:", LocationRoot::Root)); | 307 | ("r:", LocationRoot::Root), |
308 | values_ok.push(( | 308 | ( |
309 | "c:test", | 309 | "c:test", |
310 | LocationRoot::Custom("/usr/local/test".to_string()), | 310 | LocationRoot::Custom("/usr/local/test".to_string()), |
311 | )); | 311 | ), |
312 | ]; | ||
312 | 313 | ||
313 | for value in values_ok { | 314 | for value in values_ok { |
314 | println!("Testing {value:?}"); | 315 | println!("Testing {value:?}"); |
@@ -316,18 +317,19 @@ mod tests { | |||
316 | println!("\x1B[FTesting {value:?} ✓"); | 317 | println!("\x1B[FTesting {value:?} ✓"); |
317 | } | 318 | } |
318 | 319 | ||
319 | let mut values_err: Vec<(&str, String)> = Vec::new(); | 320 | let values_err = vec![ |
320 | values_err.push(( | 321 | ( |
321 | "c:rest", | 322 | "c:rest", |
322 | Error::CustomDirectory("rest".to_string()).to_string(), | 323 | Error::CustomDirectory("rest".to_string()).to_string(), |
323 | )); | 324 | ), |
324 | values_err.push(("t:test/", Error::InvalidIndex("t".to_string()).to_string())); | 325 | ("t:test/", Error::InvalidIndex("t".to_string()).to_string()), |
325 | values_err.push(( | 326 | ( |
326 | "test:test/usr", | 327 | "test:test/usr", |
327 | Error::InvalidIndex("test".to_string()).to_string(), | 328 | Error::InvalidIndex("test".to_string()).to_string(), |
328 | )); | 329 | ), |
329 | values_err.push(("/usr/local/test", Error::NoIndex.to_string())); | 330 | ("/usr/local/test", Error::NoIndex.to_string()), |
330 | values_err.push(("c/usr/local/test", Error::NoIndex.to_string())); | 331 | ("c/usr/local/test", Error::NoIndex.to_string()), |
332 | ]; | ||
331 | 333 | ||
332 | for value in values_err { | 334 | for value in values_err { |
333 | println!("Testing {value:?}"); | 335 | println!("Testing {value:?}"); |
@@ -351,47 +353,47 @@ mod tests { | |||
351 | .custom_directories | 353 | .custom_directories |
352 | .insert("test".to_string(), "/usr/local/test".to_string()); | 354 | .insert("test".to_string(), "/usr/local/test".to_string()); |
353 | 355 | ||
354 | let mut values_ok: Vec<(&str, (String, LocationRoot))> = Vec::new(); | 356 | let values_ok = vec![ |
355 | values_ok.push(( | ||
356 | "~/.config/nvim", | ||
357 | (".config/nvim".to_string(), LocationRoot::User), | ||
358 | )); | ||
359 | values_ok.push(( | ||
360 | "u:test/.config/nvim", | ||
361 | (".config/nvim".to_string(), LocationRoot::User), | ||
362 | )); | ||
363 | values_ok.push(( | ||
364 | "r:/.config/nvim", | ||
365 | (".config/nvim".to_string(), LocationRoot::Root), | ||
366 | )); | ||
367 | values_ok.push(( | ||
368 | "r:/.config/nvim", | ||
369 | (".config/nvim".to_string(), LocationRoot::Root), | ||
370 | )); | ||
371 | values_ok.push(( | ||
372 | "s:/.config/nvim", | ||
373 | (".config/nvim".to_string(), LocationRoot::SystemConfig), | ||
374 | )); | ||
375 | values_ok.push(( | ||
376 | "c:test/.config/nvim", | ||
377 | ( | 357 | ( |
378 | ".config/nvim".to_string(), | 358 | "~/.config/nvim", |
379 | LocationRoot::Custom("/usr/local/test".to_string()), | 359 | (".config/nvim".to_string(), LocationRoot::User), |
360 | ), | ||
361 | ( | ||
362 | "u:test/.config/nvim", | ||
363 | (".config/nvim".to_string(), LocationRoot::User), | ||
380 | ), | 364 | ), |
381 | )); | 365 | ( |
366 | "r:/.config/nvim", | ||
367 | (".config/nvim".to_string(), LocationRoot::Root), | ||
368 | ), | ||
369 | ( | ||
370 | "r:/.config/nvim", | ||
371 | (".config/nvim".to_string(), LocationRoot::Root), | ||
372 | ), | ||
373 | ( | ||
374 | "s:/.config/nvim", | ||
375 | (".config/nvim".to_string(), LocationRoot::SystemConfig), | ||
376 | ), | ||
377 | ( | ||
378 | "c:test/.config/nvim", | ||
379 | ( | ||
380 | ".config/nvim".to_string(), | ||
381 | LocationRoot::Custom("/usr/local/test".to_string()), | ||
382 | ), | ||
383 | ), | ||
384 | ]; | ||
382 | 385 | ||
383 | for value in values_ok { | 386 | for value in values_ok { |
384 | print!("Testing {value:?}"); | 387 | print!("Testing {value:?}"); |
385 | assert_eq!(PathInfo::parse_location(&value.0, &config)?, value.1); | 388 | assert_eq!(PathInfo::parse_location(value.0, &config)?, value.1); |
386 | println!("\x1B[FTesting {value:?} ✓"); | 389 | println!("\x1B[FTesting {value:?} ✓"); |
387 | } | 390 | } |
388 | Ok(()) | 391 | Ok(()) |
389 | } | 392 | } |
390 | 393 | ||
391 | #[test] | 394 | #[test] |
392 | fn compare_to_last_modified() -> color_eyre::Result<()> { | 395 | fn compare_to_last_modified() -> Result<()> { |
393 | let mut config = Config::default(); | 396 | let mut config = Config { root: "./backup-test".to_string(), ..Default::default() }; |
394 | config.root = "./backup-test".to_string(); | ||
395 | config | 397 | config |
396 | .directories | 398 | .directories |
397 | .push("u:fx/code/proj/arbs/backup-test-dir".to_string()); | 399 | .push("u:fx/code/proj/arbs/backup-test-dir".to_string()); |
@@ -404,7 +406,7 @@ mod tests { | |||
404 | let mut f = File::create("./backup-test-dir/nothing.txt")?; | 406 | let mut f = File::create("./backup-test-dir/nothing.txt")?; |
405 | f.write_all("unmodified".as_bytes())?; | 407 | f.write_all("unmodified".as_bytes())?; |
406 | 408 | ||
407 | let backup = Backup::create(&config, None)?; | 409 | let backup = Backup::create(&config)?; |
408 | backup.save(&config)?; | 410 | backup.save(&config)?; |
409 | 411 | ||
410 | let mut f = File::create("./backup-test-dir/size.txt")?; | 412 | let mut f = File::create("./backup-test-dir/size.txt")?; |