bakare/src/main.rs

90 lines
2.3 KiB
Rust
Raw Normal View History

2018-09-02 11:13:37 +01:00
extern crate crypto;
extern crate dir_diff;
2018-09-02 14:43:17 +01:00
extern crate tempfile;
extern crate walkdir;
2018-09-02 11:13:37 +01:00
use std::path::Path;
2018-09-02 14:43:17 +01:00
use walkdir::DirEntry;
use walkdir::Error;
use walkdir::WalkDir;
struct BackupEngine<'a> {
source_path: &'a Path,
repository_path: &'a Path,
}
impl<'a> BackupEngine<'a> {
fn new(source_path: &'a Path, repository_path: &'a Path) -> Self {
BackupEngine {
source_path,
repository_path,
}
}
2018-09-02 11:13:37 +01:00
2018-09-02 14:43:17 +01:00
fn backup(&self) -> Result<(), Error> {
let walker = WalkDir::new(self.source_path);
for maybe_entry in walker {
match maybe_entry {
Ok(entry) => self.process_entry(entry),
Err(error) => return Err(error),
}
}
Ok(())
2018-09-02 11:13:37 +01:00
}
2018-09-02 14:43:17 +01:00
fn process_entry(&self, entry: DirEntry) {
println!("{:?}", entry.path());
}
2018-09-02 11:13:37 +01:00
}
struct RestoreEngine;
impl RestoreEngine {
2018-09-02 14:18:58 +01:00
fn new(repository_path: &Path, target_path: &Path) -> Self {
2018-09-02 11:13:37 +01:00
RestoreEngine {}
}
fn restore(&self) {}
}
2018-08-17 17:58:18 +01:00
2018-09-01 09:44:13 +01:00
mod rustback {
2018-08-17 17:58:18 +01:00
2018-08-18 18:39:40 +01:00
use super::*;
#[cfg(test)]
mod should {
2018-09-01 09:44:13 +01:00
use super::*;
2018-09-02 14:43:17 +01:00
use dir_diff::is_different;
use std::fs::write;
2018-09-01 09:44:13 +01:00
use std::fs::File;
use std::io::Error;
2018-09-02 11:13:37 +01:00
use std::io::{self, Write};
use tempfile::tempdir;
use tempfile::tempfile_in;
use tempfile::TempDir;
2018-09-01 09:44:13 +01:00
2018-08-18 18:39:40 +01:00
#[test]
2018-09-01 09:44:13 +01:00
fn be_able_to_restore_backed_up_files() -> Result<(), Error> {
2018-09-02 11:13:37 +01:00
let source = tempdir()?;
2018-09-02 13:27:04 +01:00
File::create(source.path().join("first"))?.write_all("some contents".as_bytes())?;
File::create(source.path().join("second"))?.write_all("some contents".as_bytes())?;
File::create(source.path().join("third"))?.write_all("some other contents".as_bytes())?;
2018-09-01 09:44:13 +01:00
2018-09-02 14:18:58 +01:00
let repository = tempdir()?;
let backup_engine = BackupEngine::new(&source.path(), &repository.path());
2018-09-02 11:13:37 +01:00
backup_engine.backup();
2018-09-01 09:44:13 +01:00
2018-09-02 14:18:58 +01:00
let restore_target = tempdir()?;
let restore_engine = RestoreEngine::new(&repository.path(), &restore_target.path());
2018-09-02 11:13:37 +01:00
restore_engine.restore();
2018-09-01 09:44:13 +01:00
2018-09-02 14:43:17 +01:00
let are_source_and_target_different =
is_different(&source.path(), &restore_target.path()).unwrap();
assert!(!are_source_and_target_different);
2018-09-01 09:44:13 +01:00
Ok(())
}
}
2018-08-18 18:39:40 +01:00
2018-09-01 09:44:13 +01:00
}