bakare/src/restore.rs

41 lines
1 KiB
Rust
Raw Normal View History

2018-10-04 15:33:01 +01:00
use std::fs;
2018-10-04 15:29:19 +01:00
use std::path::Path;
2019-01-12 14:39:20 +00:00
2018-10-04 15:29:19 +01:00
use walkdir::DirEntry;
2019-01-12 14:39:20 +00:00
use crate::error::BakareError;
use crate::repository::Repository;
2019-01-26 19:27:23 +00:00
use crate::repository::RepositoryItem;
2019-09-01 12:57:37 +01:00
use crate::ItemVersion;
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-01-12 14:39:20 +00:00
self.restore(item)?;
}
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-01 12:57:37 +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
}
pub fn restore_as_of_version(&self, item: &RepositoryItem, version: &ItemVersion) -> Result<(), BakareError> {
2019-01-12 14:39:20 +00:00
unimplemented!()
2018-10-04 15:29:19 +01:00
}
}