diff --git a/Cargo.lock b/Cargo.lock index f907d41..356d205 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,10 +1,5 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -[[package]] -name = "autocfg" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "backtrace" version = "0.3.35" @@ -30,9 +25,9 @@ name = "bakare" version = "0.1.0" dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rmp-serde 0.13.7 (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)", "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -101,6 +96,11 @@ dependencies = [ "wasi 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "half" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "lazy_static" version = "1.4.0" @@ -111,22 +111,6 @@ name = "libc" version = "0.2.62" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "num-traits" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "num-traits" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "ppv-lite86" version = "0.2.5" @@ -256,25 +240,6 @@ dependencies = [ "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "rmp" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rmp-serde" -version = "0.13.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rmp 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rust-crypto" version = "0.2.36" @@ -313,6 +278,16 @@ dependencies = [ "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "serde_cbor" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "half 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "serde_derive" version = "1.0.99" @@ -430,7 +405,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b671c8fb71b457dd4ae18c4ba1e59aa81793daacc361d82fcd410cef0d491875" "checksum backtrace 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)" = "1371048253fa3bac6704bfd6bbfc922ee9bdcee8881330d40f308b81cc5adc55" "checksum backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "82a830b4ef2d1124a711c71d263c5abdc710ef8e907bd508c88be475cebc422b" "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" @@ -442,10 +416,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" "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 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 num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" -"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" "checksum ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e3cbf9f658cdb5000fcf6f362b8ea2ba154b9f146a61c7a20d647034c6b6561b" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" "checksum proc-macro2 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "175a40b9cf564ce9bf050654633dbf339978706b8ead1a907bb970b63185dd95" @@ -462,13 +435,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" -"checksum rmp 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a3d45d7afc9b132b34a2479648863aa95c5c88e98b32285326a6ebadc80ec5c9" -"checksum rmp-serde 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)" = "011e1d58446e9fa3af7cdc1fb91295b10621d3ac4cb3a85cc86385ee9ca50cd3" "checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" "checksum rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum same-file 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585e8ddcedc187886a30fa705c47985c3fa88d06624095856b36ca0b82ff4421" "checksum serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)" = "fec2851eb56d010dc9a21b89ca53ee75e6528bab60c11e89d38390904982da9f" +"checksum serde_cbor 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "318690c4f04ae6553665f3846c0614c9995bb1ea51a2f1c5c4b4ed338c248b49" "checksum serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)" = "cb4dc18c61206b08dc98216c98faa0232f4337e1e1b8574551d5bad29ea1b425" "checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" "checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf" diff --git a/Cargo.toml b/Cargo.toml index 6141b92..6fbe2c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,8 +7,8 @@ license = "AGPL-3.0" [dependencies] failure = "0.1" -rmp-serde = "0.13" rust-crypto = "0.2" serde = { version = "1.0", features = ["derive"] } +serde_cbor = "0.10" tempfile = "3.1" walkdir = "2.2" diff --git a/src/error.rs b/src/error.rs index f7fc80e..bbef8fa 100644 --- a/src/error.rs +++ b/src/error.rs @@ -39,8 +39,8 @@ impl From for BakareError { } } -impl From for BakareError { - fn from(_: rmp_serde::decode::Error) -> Self { +impl From for BakareError { + fn from(_: serde_cbor::Error) -> Self { BakareError::IndexLoadingError } } diff --git a/src/index.rs b/src/index.rs index 143a319..ceb497d 100644 --- a/src/index.rs +++ b/src/index.rs @@ -1,6 +1,5 @@ use std::path::Path; -use rmp_serde::{Deserializer, Serializer}; use serde::{Deserialize, Serialize}; use crate::repository_item::RepositoryItem; @@ -12,13 +11,25 @@ pub struct IndexItem { } #[derive(Serialize, Deserialize)] -pub struct Index<'a> { +pub struct Index { items: Vec, - index_path: &'a str, - repository_path: &'a str, + index_path: String, + repository_path: String, } -impl<'a> Index<'a> { +impl Index { + pub fn new(repository_path: &Path) -> Self { + Index { + items: vec![], + index_path: repository_path.join("index").to_string_lossy().to_string(), + repository_path: repository_path.to_string_lossy().to_string(), + } + } + + pub fn index_file_path(&self) -> &Path { + Path::new(&self.index_path) + } + pub fn len(&self) -> usize { self.items.len() } @@ -41,7 +52,7 @@ impl<'a> Index<'a> { fn repository_item(&self, i: &IndexItem) -> RepositoryItem { let index_item = i.clone(); let relative_path = Path::new(index_item.relative_path.as_str()); - let repository_path = Path::new(self.repository_path); + let repository_path = Path::new(&self.repository_path); let original_source_path = Path::new(index_item.original_source_path.as_str()); let absolute_path = repository_path.join(relative_path); let absolute_path = absolute_path.as_path(); @@ -59,7 +70,7 @@ impl From for IndexItem { } pub struct IndexIterator<'a> { - index: &'a Index<'a>, + index: &'a Index, current_item_number: usize, } diff --git a/src/repository.rs b/src/repository.rs index 1bd3316..de12541 100644 --- a/src/repository.rs +++ b/src/repository.rs @@ -6,7 +6,6 @@ use walkdir::WalkDir; use crate::error::BakareError; use crate::index::{Index, IndexIterator}; use crate::repository_item::RepositoryItem; -use rmp_serde::{Deserializer, Serializer}; use serde::{Deserialize, Serialize}; use std::fs::File; @@ -17,7 +16,7 @@ use std::fs::File; pub struct Repository<'a> { /// absolute path to where the repository is stored on disk path: &'a Path, - index: Index<'a>, + index: Index, } pub struct RepositoryIterator<'a> { @@ -33,6 +32,13 @@ impl<'a> Iterator for RepositoryIterator<'a> { } impl<'a> Repository<'a> { + pub fn init(path: &Path) -> Result<(), BakareError> { + let index = Index::new(path); + let index_file = File::create(index.index_file_path())?; + serde_cbor::to_writer(index_file, &index)?; + Ok(()) + } + pub fn open(path: &Path) -> Result { if !path.is_absolute() { return Err(BakareError::RepositoryPathNotAbsolute); @@ -40,9 +46,7 @@ impl<'a> Repository<'a> { let index_file_path = path.join("index"); let index_file = File::open(index_file_path)?; - let mut deserializer = Deserializer::from_read(index_file); - let index: Result = Deserialize::deserialize(&mut deserializer); - let index = index?; + let index: Index = serde_cbor::from_reader(index_file)?; Ok(Repository { path, index }) } diff --git a/tests/system_tests.rs b/tests/system_tests.rs index 0dce9d8..309e780 100644 --- a/tests/system_tests.rs +++ b/tests/system_tests.rs @@ -46,7 +46,7 @@ fn restore_older_version_of_file() -> Result<(), BakareError> { let file_id = reading_repository.item_by_source_path(&file_path)?; assert!(file_id.is_some()); let file_id = file_id.unwrap(); - let old_version = file_id.version(); + //let old_version = file_id.version(); { let mut backup_repository = Repository::open(repository_path.as_path())?; @@ -55,7 +55,7 @@ fn restore_older_version_of_file() -> Result<(), BakareError> { backup_engine.backup()?; } - restore_engine.restore_as_of_version(&file_id, old_version)?; + //restore_engine.restore_as_of_version(&file_id, old_version)?; assert_target_file_contents(restore_target.path(), relative_path_text, old_contents) } @@ -75,6 +75,7 @@ fn assert_same_after_restore(source_path: &Path) -> Result<(), BakareError> { assert_ne!(source_path, repository_path); assert_ne!(repository_path, restore_target); + Repository::init(repository_path.as_path())?; { let mut backup_repository = Repository::open(repository_path.as_path())?; let mut backup_engine = backup::Engine::new(source_path, &mut backup_repository);