bakare/src/backup.rs

29 lines
698 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
2018-10-04 15:29:19 +01:00
use walkdir::WalkDir;
2019-01-12 14:39:20 +00:00
use crate::error::BakareError;
use crate::repository::Repository;
2018-10-04 15:33:01 +01:00
pub struct Engine<'a> {
2018-10-04 15:29:19 +01:00
source_path: &'a Path,
2019-09-01 11:05:22 +01:00
repository: &'a mut Repository<'a>,
2018-12-22 16:09:22 +00:00
}
2018-10-04 15:33:01 +01:00
impl<'a> Engine<'a> {
2019-09-01 11:05:22 +01:00
pub fn new(source_path: &'a Path, repository: &'a mut Repository<'a>) -> Self {
2019-01-12 14:42:53 +00:00
Engine { source_path, repository }
2018-10-04 15:29:19 +01:00
}
2019-09-01 11:05:22 +01:00
pub fn backup(&mut self) -> Result<(), BakareError> {
2018-10-04 15:29:19 +01:00
let walker = WalkDir::new(self.source_path);
for maybe_entry in walker {
let entry = maybe_entry?;
if entry.path() != self.source_path {
2019-01-26 19:27:23 +00:00
self.repository.store(entry.path())?;
2018-10-04 15:29:19 +01:00
}
}
Ok(())
}
}