add walker

This commit is contained in:
Cyryl Płotnicki 2018-09-02 14:43:17 +01:00
parent 4f7fef37d2
commit 4542fa5cd0
3 changed files with 37 additions and 11 deletions

1
Cargo.lock generated
View file

@ -112,6 +112,7 @@ dependencies = [
"dir-diff 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 3.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"walkdir 2.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]

View file

@ -4,6 +4,7 @@ version = "0.1.0"
authors = ["Cyryl Płotnicki <cyplo@cyplo.net>"]
[dependencies]
walkdir = "2.2"
[dev-dependencies]
tempfile = "3.0"

View file

@ -1,16 +1,40 @@
extern crate crypto;
extern crate tempfile;
extern crate dir_diff;
extern crate tempfile;
extern crate walkdir;
use std::path::Path;
use walkdir::DirEntry;
use walkdir::Error;
use walkdir::WalkDir;
struct BackupEngine;
impl BackupEngine {
fn new(source_path: &Path, repository_path: &Path) -> Self {
BackupEngine {}
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,
}
}
fn backup(&self) {}
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(())
}
fn process_entry(&self, entry: DirEntry) {
println!("{:?}", entry.path());
}
}
struct RestoreEngine;
@ -30,14 +54,14 @@ mod rustback {
mod should {
use super::*;
use dir_diff::is_different;
use std::fs::write;
use std::fs::File;
use std::io::Error;
use std::io::{self, Write};
use tempfile::tempdir;
use tempfile::tempfile_in;
use tempfile::TempDir;
use dir_diff::is_different;
use std::fs::write;
#[test]
fn be_able_to_restore_backed_up_files() -> Result<(), Error> {
@ -55,11 +79,11 @@ mod rustback {
let restore_engine = RestoreEngine::new(&repository.path(), &restore_target.path());
restore_engine.restore();
let is_source_and_destination_different = is_different(&source.path(), &restore_target.path()).unwrap();
assert!(!is_source_and_destination_different);
let are_source_and_target_different =
is_different(&source.path(), &restore_target.path()).unwrap();
assert!(!are_source_and_target_different);
Ok(())
}
}
}