bakare/src/restore.rs

32 lines
824 B
Rust
Raw Normal View History

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-23 12:18:18 +01:00
for item in self.repository.newest_items() {
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-09-07 13:58:32 +01:00
pub fn restore(&self, item: &RepositoryItem) -> Result<(), BakareError> {
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
}
}