bakare/src/restore.rs

54 lines
1.3 KiB
Rust
Raw Normal View History

2019-01-12 14:39:20 +00:00
use std::error::Error;
2018-10-04 15:33:01 +01:00
use std::fs;
2018-10-04 15:29:19 +01:00
use std::io;
use std::path::Path;
2019-01-12 14:39:20 +00:00
2018-10-04 15:29:19 +01:00
use walkdir::DirEntry;
2018-10-04 15:33:01 +01:00
use walkdir::WalkDir;
2018-10-04 15:29:19 +01:00
2019-01-12 14:39:20 +00:00
use crate::error::BakareError;
use crate::repository::Repository;
use crate::repository::StoredItemId;
use crate::Version;
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-01-12 14:39:20 +00:00
pub fn new(repository: &'a Repository, target_path: &'a Path) -> Self {
2018-10-04 15:33:01 +01:00
Engine {
2019-01-12 14:39:20 +00:00
repository,
2018-10-04 15:29:19 +01:00
target_path,
}
}
2019-01-12 14:39:20 +00:00
pub fn restore_all(&self) -> Result<(), BakareError> {
for item in self.repository {
self.restore(item)?;
}
Ok(())
2018-10-04 15:29:19 +01:00
}
2019-01-12 14:39:20 +00:00
fn restore(&self, item: StoredItemId) -> Result<(), BakareError> {
let version = self.repository.newest_version_for(&item)?;
self.restore_as_of_version(item, version)
2018-10-04 15:29:19 +01:00
}
2019-01-12 14:39:20 +00:00
pub fn restore_as_of_version(&self, what: StoredItemId, version: Version) -> Result<(), BakareError> {
unimplemented!()
2018-10-04 15:29:19 +01:00
}
2019-01-12 14:39:20 +00:00
fn process_entry(&self, entry: &DirEntry) -> Result<(), BakareError> {
2018-10-04 15:29:19 +01:00
if entry.file_type().is_dir() {
fs::create_dir(self.target_path.join(entry.file_name()))?;
}
if entry.file_type().is_file() {
fs::copy(entry.path(), self.target_path.join(entry.file_name()))?;
}
Ok(())
}
}