2018-10-04 15:29:19 +01:00
|
|
|
use std::path::Path;
|
2019-01-12 14:39:20 +00:00
|
|
|
|
|
|
|
use crate::error::BakareError;
|
|
|
|
use crate::repository::Repository;
|
2019-09-01 20:10:00 +01:00
|
|
|
use crate::repository_item::RepositoryItem;
|
2019-01-12 14:39:20 +00:00
|
|
|
|
2018-10-04 15:33:01 +01:00
|
|
|
pub struct Engine<'a> {
|
2019-01-12 14:39:20 +00:00
|
|
|
repository: &'a Repository<'a>,
|
2018-10-04 15:29:19 +01:00
|
|
|
target_path: &'a Path,
|
|
|
|
}
|
|
|
|
|
2018-10-04 15:33:01 +01:00
|
|
|
impl<'a> Engine<'a> {
|
2019-09-01 17:03:27 +01:00
|
|
|
pub fn new(repository: &'a Repository, target_path: &'a Path) -> Result<Self, BakareError> {
|
|
|
|
if !target_path.is_absolute() {
|
|
|
|
return Err(BakareError::PathToStoreNotAbsolute);
|
|
|
|
}
|
|
|
|
Ok(Engine { repository, target_path })
|
2018-10-04 15:29:19 +01:00
|
|
|
}
|
|
|
|
|
2019-01-12 14:39:20 +00:00
|
|
|
pub fn restore_all(&self) -> Result<(), BakareError> {
|
2019-09-01 12:57:37 +01:00
|
|
|
for item in self.repository.iter() {
|
2019-09-01 20:10:00 +01:00
|
|
|
self.restore(&item)?;
|
2019-01-12 14:39:20 +00:00
|
|
|
}
|
|
|
|
Ok(())
|
2018-10-04 15:29:19 +01:00
|
|
|
}
|
|
|
|
|
2019-01-26 19:27:23 +00:00
|
|
|
fn restore(&self, item: &RepositoryItem) -> Result<(), BakareError> {
|
2019-09-07 09:51:38 +01:00
|
|
|
println!("restoring {}", item);
|
2019-09-01 17:03:27 +01:00
|
|
|
item.save(self.target_path)?;
|
2019-09-01 12:57:37 +01:00
|
|
|
Ok(())
|
2018-10-04 15:29:19 +01:00
|
|
|
}
|
|
|
|
}
|