From 14490bbe78e9ba282c6bb34edccf4f959ebb7424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cyryl=20P=C5=82otnicki?= Date: Sat, 7 Sep 2019 09:01:30 +0100 Subject: [PATCH] better verbosity --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + src/index.rs | 2 +- src/repository.rs | 2 +- src/repository_item.rs | 16 +++++++++++++--- tests/system_tests.rs | 4 ++-- 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5f8d8cd..f462b6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,6 +25,7 @@ name = "bakare" version = "0.1.0" dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_cbor 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -147,6 +148,11 @@ name = "half" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "hex" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "lazy_static" version = "1.4.0" @@ -490,6 +496,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" "checksum getrandom 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "fc344b02d3868feb131e8b5fe2b9b0a1cc42942679af493061fc13b853243872" "checksum half 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9353c2a89d550b58fa0061d8ed8d002a7d8cdf2494eb0e432859bd3a9e543836" +"checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" "checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba" "checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" diff --git a/Cargo.toml b/Cargo.toml index c66f1b1..2fed9cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,3 +13,4 @@ serde_cbor = "0.10" tempfile = "3.1" walkdir = "2.2" sha2 = "0.8" +hex = "0.3" diff --git a/src/index.rs b/src/index.rs index 4bfed43..f7685dc 100644 --- a/src/index.rs +++ b/src/index.rs @@ -47,7 +47,7 @@ impl Index { } pub fn remember(&mut self, item: RepositoryItem) { - println!("remembering {:#?}", item); + println!("remembering {}", item); self.items.push(item.into()); } diff --git a/src/repository.rs b/src/repository.rs index 0fcbb71..cd6c3e3 100644 --- a/src/repository.rs +++ b/src/repository.rs @@ -7,7 +7,7 @@ use crate::repository_item::RepositoryItem; use sha2::Digest; use sha2::Sha512; use std::fs::File; -use std::io::{BufReader, Read}; +use std::io::BufReader; /// represents a place where backup is stored an can be restored from. /// right now only on-disk directory storage is supported diff --git a/src/repository_item.rs b/src/repository_item.rs index 2f1f8ac..06bd323 100644 --- a/src/repository_item.rs +++ b/src/repository_item.rs @@ -1,8 +1,7 @@ use crate::error::BakareError; -use sha2::digest::DynDigest; -use sha2::{Digest, Sha512}; -use std::fs; +use std::fmt::{Display, Formatter}; use std::path::Path; +use std::{fmt, fs}; #[derive(Clone, Debug, PartialOrd, PartialEq, Ord, Eq)] pub struct RepositoryItem { @@ -53,3 +52,14 @@ impl RepositoryItem { self.version.clone() } } + +impl Display for RepositoryItem { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + write!( + f, + "'{}' : {}", + self.original_source_path().to_string_lossy(), + hex::encode(self.version()) + ) + } +} diff --git a/tests/system_tests.rs b/tests/system_tests.rs index c53390c..4073571 100644 --- a/tests/system_tests.rs +++ b/tests/system_tests.rs @@ -74,7 +74,7 @@ fn restore_older_version_of_file() -> Result<(), BakareError> { let item = reading_repository.item_by_source_path(&file_path)?; assert!(item.is_some()); let item = item.unwrap(); - let old_version = item.version(); + let _old_version = item.version(); { let new_contents = "totally new contents"; @@ -86,7 +86,7 @@ fn restore_older_version_of_file() -> Result<(), BakareError> { let restore_repository = Repository::open(repository_path.as_path())?; let restore_target = tempdir()?; - let restore_engine = restore::Engine::new(&restore_repository, &restore_target.path())?; + let _restore_engine = restore::Engine::new(&restore_repository, &restore_target.path())?; //restore_engine.restore_as_of_version(&item, old_version)?; assert_target_file_contents(restore_target.path(), relative_path_text, old_contents)