2019-01-12 14:39:20 +00:00
|
|
|
use std::error::Error;
|
|
|
|
use std::fs;
|
|
|
|
use std::io;
|
|
|
|
use std::path::Path;
|
|
|
|
|
|
|
|
use walkdir::DirEntry;
|
|
|
|
|
|
|
|
use crate::error::BakareError;
|
|
|
|
use crate::Version;
|
2019-01-26 20:11:11 +00:00
|
|
|
use crate::Index;
|
2019-01-12 14:39:20 +00:00
|
|
|
|
2019-01-26 19:27:23 +00:00
|
|
|
/// represents a place where backup is stored an can be restored from.
|
|
|
|
/// right now only on-disk directory storage is supported
|
2019-01-12 14:39:20 +00:00
|
|
|
pub struct Repository<'a> {
|
2019-01-26 19:27:23 +00:00
|
|
|
/// absolute path to where the repository is stored on disk
|
2019-01-12 14:42:53 +00:00
|
|
|
path: &'a Path,
|
2019-01-26 20:11:11 +00:00
|
|
|
index: Index
|
2019-01-12 14:39:20 +00:00
|
|
|
}
|
|
|
|
|
2019-01-26 19:27:23 +00:00
|
|
|
pub struct RepositoryItem {
|
|
|
|
version: Version
|
|
|
|
}
|
|
|
|
|
2019-01-26 20:11:11 +00:00
|
|
|
pub struct RepositoryIterator;
|
|
|
|
|
|
|
|
impl<'a> Iterator for RepositoryIterator {
|
2019-01-26 19:27:23 +00:00
|
|
|
type Item = RepositoryItem;
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl RepositoryItem {
|
|
|
|
pub fn version(&self) -> &Version {
|
|
|
|
&self.version
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-12 14:39:20 +00:00
|
|
|
impl<'a> Repository<'a> {
|
2019-01-26 20:11:11 +00:00
|
|
|
pub fn open(path: &Path) -> Result<Repository, BakareError> {
|
|
|
|
// TODO open index from file
|
|
|
|
|
|
|
|
Ok(Repository { path, index: Index {} })
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn iter(&self) -> RepositoryIterator {
|
|
|
|
unimplemented!()
|
2019-01-12 14:39:20 +00:00
|
|
|
}
|
|
|
|
|
2019-01-26 19:27:23 +00:00
|
|
|
pub fn store(&self, source_path: &Path) -> Result<(), BakareError> {
|
2019-01-12 14:39:20 +00:00
|
|
|
// get file id -> contents hash + original path + time of taking notes
|
|
|
|
// get storage path for File
|
|
|
|
// store file contents
|
|
|
|
// remember File
|
|
|
|
|
2019-01-26 19:27:23 +00:00
|
|
|
if source_path.is_dir() {
|
|
|
|
fs::create_dir(self.path.join(source_path))?;
|
2019-01-12 14:39:20 +00:00
|
|
|
}
|
2019-01-26 19:27:23 +00:00
|
|
|
if source_path.is_file() {
|
|
|
|
fs::copy(source_path, self.path.join(source_path))?;
|
2019-01-12 14:39:20 +00:00
|
|
|
}
|
|
|
|
|
2019-01-26 19:27:23 +00:00
|
|
|
// TODO create new version, remember source_path
|
2019-01-12 14:39:20 +00:00
|
|
|
|
2019-01-26 19:27:23 +00:00
|
|
|
Ok(())
|
2019-01-12 14:39:20 +00:00
|
|
|
}
|
|
|
|
|
2019-01-26 19:27:23 +00:00
|
|
|
pub fn item(&self, path: &Path) -> Option<RepositoryItem> {
|
2019-01-12 14:39:20 +00:00
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
2019-01-26 19:27:23 +00:00
|
|
|
pub fn newest_version_for(&self, source_path: &Path) -> Result<Version, BakareError> {
|
2019-01-12 14:39:20 +00:00
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-01-26 19:27:23 +00:00
|
|
|
|