WIP on index - needs original source path stored

This commit is contained in:
Cyryl Płotnicki 2019-09-01 17:39:42 +01:00
parent 4800901f23
commit ae4ed1f985
2 changed files with 13 additions and 14 deletions

View file

@ -24,6 +24,7 @@ pub struct RepositoryItem<'a> {
version: ItemVersion<'a>, version: ItemVersion<'a>,
relative_path: Box<Path>, relative_path: Box<Path>,
absolute_path: Box<Path>, absolute_path: Box<Path>,
original_source_path: Box<Path>,
} }
pub struct RepositoryIterator<'a> { pub struct RepositoryIterator<'a> {
@ -140,19 +141,17 @@ impl<'a> Repository<'a> {
Ok(()) Ok(())
} }
pub fn item(&self, path: &Path) -> Option<&RepositoryItem> { pub fn item_by_source_path(&self, path: &Path) -> Result<Option<&RepositoryItem>, BakareError> {
let relative_path = { println!(
if path.is_relative() { "trying to find {} in a repo [{}] of {} items",
Some(path) path.display(),
} else { self.path.display(),
path.strip_prefix(self.path).ok() self.index.items.len()
} );
}; if !path.is_absolute() {
if let Some(relative_path) = relative_path { return Err(BakareError::RepositoryPathNotAbsolute);
self.index.items.iter().find(|i| *i.relative_path == *relative_path)
} else {
None
} }
self.index.items.iter().find(|i| *i.original_source_path == *path)
} }
pub fn newest_version_for(&self, item: RepositoryItem) -> ItemVersion { pub fn newest_version_for(&self, item: RepositoryItem) -> ItemVersion {

View file

@ -42,8 +42,8 @@ fn restore_older_version_of_file() -> Result<(), BakareError> {
backup_engine.backup()?; backup_engine.backup()?;
} }
let backup_repository = Repository::open(repository_path.as_path())?; let reading_repository = Repository::open(repository_path.as_path())?;
let file_id = backup_repository.item(&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();