cleanup
This commit is contained in:
parent
2a96cd2396
commit
4e76d046d1
5 changed files with 17 additions and 31 deletions
|
@ -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(())
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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>,
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<Repository, BakareError> {
|
||||
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!()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue