bakare/src/restore.rs

49 lines
1.2 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::Version;
2019-01-26 19:27:23 +00:00
use crate::repository::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-01-12 14:39:20 +00:00
pub fn new(repository: &'a Repository, target_path: &'a Path) -> Self {
2019-01-12 14:42:53 +00:00
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-01-26 20:11:11 +00:00
for ref 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> {
unimplemented!()
2018-10-04 15:29:19 +01:00
}
2019-01-26 19:27:23 +00:00
pub fn restore_as_of_version(&self, item: &RepositoryItem, version: &Version) -> Result<(), BakareError> {
2019-01-12 14:39:20 +00:00
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(())
}
}