back to the point where one test works

This commit is contained in:
Cyryl Płotnicki 2019-09-01 21:19:40 +01:00
parent 18881df4a9
commit 36cff8cb06
6 changed files with 51 additions and 63 deletions

64
Cargo.lock generated
View file

@ -1,10 +1,5 @@
# This file is automatically @generated by Cargo. # This file is automatically @generated by Cargo.
# It is not intended for manual editing. # 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]] [[package]]
name = "backtrace" name = "backtrace"
version = "0.3.35" version = "0.3.35"
@ -30,9 +25,9 @@ name = "bakare"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "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 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)", "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)", "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)", "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]] [[package]]
name = "lazy_static" name = "lazy_static"
version = "1.4.0" version = "1.4.0"
@ -111,22 +111,6 @@ name = "libc"
version = "0.2.62" version = "0.2.62"
source = "registry+https://github.com/rust-lang/crates.io-index" 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]] [[package]]
name = "ppv-lite86" name = "ppv-lite86"
version = "0.2.5" version = "0.2.5"
@ -256,25 +240,6 @@ dependencies = [
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "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]] [[package]]
name = "rust-crypto" name = "rust-crypto"
version = "0.2.36" version = "0.2.36"
@ -313,6 +278,16 @@ dependencies = [
"serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "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]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.99" version = "1.0.99"
@ -430,7 +405,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata] [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 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 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" "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 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 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 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 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 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 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 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" "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 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 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 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 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-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 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 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 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 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 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" "checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf"

View file

@ -7,8 +7,8 @@ license = "AGPL-3.0"
[dependencies] [dependencies]
failure = "0.1" failure = "0.1"
rmp-serde = "0.13"
rust-crypto = "0.2" rust-crypto = "0.2"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_cbor = "0.10"
tempfile = "3.1" tempfile = "3.1"
walkdir = "2.2" walkdir = "2.2"

View file

@ -39,8 +39,8 @@ impl From<StripPrefixError> for BakareError {
} }
} }
impl From<rmp_serde::decode::Error> for BakareError { impl From<serde_cbor::Error> for BakareError {
fn from(_: rmp_serde::decode::Error) -> Self { fn from(_: serde_cbor::Error) -> Self {
BakareError::IndexLoadingError BakareError::IndexLoadingError
} }
} }

View file

@ -1,6 +1,5 @@
use std::path::Path; use std::path::Path;
use rmp_serde::{Deserializer, Serializer};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::repository_item::RepositoryItem; use crate::repository_item::RepositoryItem;
@ -12,13 +11,25 @@ pub struct IndexItem {
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
pub struct Index<'a> { pub struct Index {
items: Vec<IndexItem>, items: Vec<IndexItem>,
index_path: &'a str, index_path: String,
repository_path: &'a str, repository_path: String,
}
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)
} }
impl<'a> Index<'a> {
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.items.len() self.items.len()
} }
@ -41,7 +52,7 @@ impl<'a> Index<'a> {
fn repository_item(&self, i: &IndexItem) -> RepositoryItem { fn repository_item(&self, i: &IndexItem) -> RepositoryItem {
let index_item = i.clone(); let index_item = i.clone();
let relative_path = Path::new(index_item.relative_path.as_str()); 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 original_source_path = Path::new(index_item.original_source_path.as_str());
let absolute_path = repository_path.join(relative_path); let absolute_path = repository_path.join(relative_path);
let absolute_path = absolute_path.as_path(); let absolute_path = absolute_path.as_path();
@ -59,7 +70,7 @@ impl From<RepositoryItem> for IndexItem {
} }
pub struct IndexIterator<'a> { pub struct IndexIterator<'a> {
index: &'a Index<'a>, index: &'a Index,
current_item_number: usize, current_item_number: usize,
} }

View file

@ -6,7 +6,6 @@ use walkdir::WalkDir;
use crate::error::BakareError; use crate::error::BakareError;
use crate::index::{Index, IndexIterator}; use crate::index::{Index, IndexIterator};
use crate::repository_item::RepositoryItem; use crate::repository_item::RepositoryItem;
use rmp_serde::{Deserializer, Serializer};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fs::File; use std::fs::File;
@ -17,7 +16,7 @@ use std::fs::File;
pub struct Repository<'a> { pub struct Repository<'a> {
/// absolute path to where the repository is stored on disk /// absolute path to where the repository is stored on disk
path: &'a Path, path: &'a Path,
index: Index<'a>, index: Index,
} }
pub struct RepositoryIterator<'a> { pub struct RepositoryIterator<'a> {
@ -33,6 +32,13 @@ impl<'a> Iterator for RepositoryIterator<'a> {
} }
impl<'a> Repository<'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<Repository, BakareError> { pub fn open(path: &Path) -> Result<Repository, BakareError> {
if !path.is_absolute() { if !path.is_absolute() {
return Err(BakareError::RepositoryPathNotAbsolute); return Err(BakareError::RepositoryPathNotAbsolute);
@ -40,9 +46,7 @@ impl<'a> Repository<'a> {
let index_file_path = path.join("index"); let index_file_path = path.join("index");
let index_file = File::open(index_file_path)?; let index_file = File::open(index_file_path)?;
let mut deserializer = Deserializer::from_read(index_file); let index: Index = serde_cbor::from_reader(index_file)?;
let index: Result<Index, _> = Deserialize::deserialize(&mut deserializer);
let index = index?;
Ok(Repository { path, index }) Ok(Repository { path, index })
} }

View file

@ -46,7 +46,7 @@ fn restore_older_version_of_file() -> Result<(), BakareError> {
let file_id = reading_repository.item_by_source_path(&file_path)?; let file_id = reading_repository.item_by_source_path(&file_path)?;
assert!(file_id.is_some()); assert!(file_id.is_some());
let file_id = file_id.unwrap(); 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())?; 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()?; 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) 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!(source_path, repository_path);
assert_ne!(repository_path, restore_target); 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_repository = Repository::open(repository_path.as_path())?;
let mut backup_engine = backup::Engine::new(source_path, &mut backup_repository); let mut backup_engine = backup::Engine::new(source_path, &mut backup_repository);