diff --git a/src/backup.rs b/src/backup.rs index 09ab137..1d0e130 100644 --- a/src/backup.rs +++ b/src/backup.rs @@ -9,7 +9,6 @@ use walkdir::WalkDir; use crate::error::BakareError; use crate::repository::Repository; -use crate::RepositoryRelativePath; use crate::Version; pub struct Engine<'a> { diff --git a/src/lib.rs b/src/lib.rs index 76c76e0..c3ade8b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,8 +13,6 @@ pub mod source; pub mod repository; pub struct Version(String); -struct RepositoryRelativePath {} -struct Index<'a> { - versions: HashMap<&'a RepositoryRelativePath, &'a Version>, +struct Index { } diff --git a/src/repository.rs b/src/repository.rs index e215b25..8d9606a 100644 --- a/src/repository.rs +++ b/src/repository.rs @@ -7,19 +7,23 @@ use walkdir::DirEntry; use crate::error::BakareError; use crate::Version; +use crate::Index; /// represents a place where backup is stored an can be restored from. /// right now only on-disk directory storage is supported pub struct Repository<'a> { /// absolute path to where the repository is stored on disk path: &'a Path, + index: Index } pub struct RepositoryItem { version: Version } -impl<'a> Iterator for &Repository<'a> { +pub struct RepositoryIterator; + +impl<'a> Iterator for RepositoryIterator { type Item = RepositoryItem; fn next(&mut self) -> Option { @@ -34,8 +38,14 @@ impl RepositoryItem { } impl<'a> Repository<'a> { - pub fn new(path: &Path) -> Result { - Ok(Repository { path }) + pub fn open(path: &Path) -> Result { + // TODO open index from file + + Ok(Repository { path, index: Index {} }) + } + + pub fn iter(&self) -> RepositoryIterator { + unimplemented!() } pub fn store(&self, source_path: &Path) -> Result<(), BakareError> { diff --git a/src/restore.rs b/src/restore.rs index a210dcd..4c7845f 100644 --- a/src/restore.rs +++ b/src/restore.rs @@ -22,7 +22,7 @@ impl<'a> Engine<'a> { } pub fn restore_all(&self) -> Result<(), BakareError> { - for ref item in self.repository { + for ref item in self.repository.iter() { self.restore(item)?; } Ok(()) diff --git a/tests/system_tests.rs b/tests/system_tests.rs index 8b784a5..1ea7e7e 100644 --- a/tests/system_tests.rs +++ b/tests/system_tests.rs @@ -26,7 +26,7 @@ fn restore_backed_up_files() -> Result<(), BakareError> { fn restore_older_version_of_file() -> Result<(), BakareError> { let source = TempSource::new()?; let repository_path = tempdir()?.into_path(); - let repository = Repository::new(repository_path.as_path())?; + let repository = Repository::open(repository_path.as_path())?; let backup_engine = backup::Engine::new(source.path(), &repository); let relative_path_text = "some path"; let file_path = source.file_path(relative_path_text); @@ -58,7 +58,7 @@ fn assert_target_file_contents(target: &Path, filename: &str, expected_contents: 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 repository = Repository::open(repository_path.as_path())?; let backup_engine = backup::Engine::new(source_path, &repository); backup_engine.backup()?;