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>,
relative_path: Box<Path>,
absolute_path: Box<Path>,
original_source_path: Box<Path>,
}
pub struct RepositoryIterator<'a> {
@ -140,19 +141,17 @@ impl<'a> Repository<'a> {
Ok(())
}
pub fn item(&self, path: &Path) -> Option<&RepositoryItem> {
let relative_path = {
if path.is_relative() {
Some(path)
} else {
path.strip_prefix(self.path).ok()
}
};
if let Some(relative_path) = relative_path {
self.index.items.iter().find(|i| *i.relative_path == *relative_path)
} else {
None
pub fn item_by_source_path(&self, path: &Path) -> Result<Option<&RepositoryItem>, BakareError> {
println!(
"trying to find {} in a repo [{}] of {} items",
path.display(),
self.path.display(),
self.index.items.len()
);
if !path.is_absolute() {
return Err(BakareError::RepositoryPathNotAbsolute);
}
self.index.items.iter().find(|i| *i.original_source_path == *path)
}
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()?;
}
let backup_repository = Repository::open(repository_path.as_path())?;
let file_id = backup_repository.item(&file_path);
let reading_repository = Repository::open(repository_path.as_path())?;
let file_id = reading_repository.item_by_source_path(&file_path)?;
assert!(file_id.is_some());
let file_id = file_id.unwrap();
let old_version = file_id.version();