diff --git a/src/backup.rs b/src/backup.rs index 46fe18c..3608e89 100644 --- a/src/backup.rs +++ b/src/backup.rs @@ -14,16 +14,12 @@ use crate::Version; pub struct Engine<'a> { source_path: &'a Path, - repository: &'a Repository<'a> + repository: &'a Repository<'a>, } - impl<'a> Engine<'a> { pub fn new(source_path: &'a Path, repository: &'a Repository) -> Self { - Engine { - source_path, - repository, - } + Engine { source_path, repository } } pub fn backup(&self) -> Result<(), BakareError> { @@ -36,5 +32,4 @@ impl<'a> Engine<'a> { } Ok(()) } - } diff --git a/src/lib.rs b/src/lib.rs index 9995152..76c76e0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,8 +5,8 @@ use std::io; use failure::Fail; -pub mod error; pub mod backup; +pub mod error; pub mod restore; pub mod source; @@ -18,5 +18,3 @@ struct RepositoryRelativePath {} struct Index<'a> { versions: HashMap<&'a RepositoryRelativePath, &'a Version>, } - - diff --git a/src/repository.rs b/src/repository.rs index 99cec3d..ae5f1f1 100644 --- a/src/repository.rs +++ b/src/repository.rs @@ -10,16 +10,14 @@ use crate::Version; /// represents a place where backup is stored an can be restored from. E.g. a directory, a cloud service etc pub struct Repository<'a> { - path: &'a Path + path: &'a Path, } pub struct StoredItemId; pub struct RelativePath; impl<'a> Repository<'a> { pub fn new(path: &Path) -> Result { - Ok(Repository { - path - }) + Ok(Repository { path }) } pub fn store_entry(&self, entry: &DirEntry) -> Result<(), BakareError> { @@ -65,4 +63,3 @@ impl<'a> Iterator for &Repository<'a> { unimplemented!() } } - diff --git a/src/restore.rs b/src/restore.rs index 4032eee..344b0bc 100644 --- a/src/restore.rs +++ b/src/restore.rs @@ -16,13 +16,9 @@ pub struct Engine<'a> { target_path: &'a Path, } - impl<'a> Engine<'a> { pub fn new(repository: &'a Repository, target_path: &'a Path) -> Self { - Engine { - repository, - target_path, - } + Engine { repository, target_path } } pub fn restore_all(&self) -> Result<(), BakareError> { diff --git a/tests/system_tests.rs b/tests/system_tests.rs index cab812f..152ba6d 100644 --- a/tests/system_tests.rs +++ b/tests/system_tests.rs @@ -3,25 +3,23 @@ use bakare::restore; use bakare::source::Source; +use bakare::error::BakareError; +use bakare::repository::Repository; use dir_diff::is_different; use std::fs::File; use std::io::Read; use std::path::Path; use tempfile::tempdir; -use bakare::error::BakareError; -use bakare::repository::Repository; #[test] fn restore_backed_up_files() -> Result<(), BakareError> { let source = Source::new()?; - let repository_path = tempdir()?.into_path(); - let repository = Repository::new(repository_path.as_path())?; source.write_text_to_file("first", "some contents")?; source.write_text_to_file("second", "some contents")?; source.write_text_to_file("third", "some other contents")?; - assert_same_after_restore(source.path(), &repository) + assert_same_after_restore(source.path()) } #[test] @@ -51,9 +49,6 @@ fn restore_older_version_of_file() -> Result<(), BakareError> { Ok(()) } -// TODO: restore latest version by default -// TODO: deduplicate data - fn assert_target_file_contents(target: &Path, filename: &str, expected_contents: &str) -> Result<(), BakareError> { let restored_path = target.join(filename); let mut actual_contents = String::new(); @@ -62,15 +57,20 @@ fn assert_target_file_contents(target: &Path, filename: &str, expected_contents: Ok(()) } -fn assert_same_after_restore(source_path: &Path, repository: &Repository) -> Result<(), BakareError> { - let backup_engine = backup::Engine::new(source_path, repository); +fn assert_same_after_restore(source_path: &Path) -> Result<(), BakareError> { + let repository_path = tempdir()?.into_path(); + let repository = Repository::new(repository_path.as_path())?; + let backup_engine = backup::Engine::new(source_path, &repository); backup_engine.backup()?; let restore_target = tempdir()?; - let restore_engine = restore::Engine::new(repository, &restore_target.path()); + let restore_engine = restore::Engine::new(&repository, &restore_target.path()); restore_engine.restore_all()?; let are_source_and_target_different = is_different(source_path, &restore_target.path()).unwrap(); assert!(!are_source_and_target_different); Ok(()) } + +// TODO: restore latest version by default +// TODO: deduplicate data