bakare/src/restore.rs

29 lines
733 B
Rust
Raw Normal View History

2020-11-08 20:02:26 +00:00
use crate::repository::{item::RepositoryItem, Repository};
use anyhow::Result;
2020-12-25 21:52:40 +00:00
use vfs::VfsPath;
2019-01-12 14:39:20 +00:00
2018-10-04 15:33:01 +01:00
pub struct Engine<'a> {
2020-12-25 16:29:00 +00:00
repository: &'a mut Repository,
2020-12-25 21:52:40 +00:00
target_path: &'a VfsPath,
2018-10-04 15:29:19 +01:00
}
2018-10-04 15:33:01 +01:00
impl<'a> Engine<'a> {
2020-12-25 21:52:40 +00:00
pub fn new(repository: &'a mut Repository, target_path: &'a VfsPath) -> Result<Self> {
2019-09-01 17:03:27 +01:00
Ok(Engine { repository, target_path })
2018-10-04 15:29:19 +01:00
}
pub fn restore_all(&mut self) -> Result<()> {
2020-12-25 21:52:40 +00:00
let newest_items = self.repository.newest_items();
for item in newest_items {
2019-09-01 20:10:00 +01:00
self.restore(&item)?;
2019-01-12 14:39:20 +00:00
}
self.repository.save_index()?;
2019-01-12 14:39:20 +00:00
Ok(())
2018-10-04 15:29:19 +01:00
}
pub fn restore(&self, item: &RepositoryItem) -> Result<()> {
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
}
}