Start testing index
This commit is contained in:
parent
5ec019d16c
commit
4a7be9bd49
5 changed files with 56 additions and 4 deletions
|
@ -5,6 +5,7 @@ authors = ["Cyryl Płotnicki <cyplo@cyplo.net>"]
|
|||
|
||||
[dependencies]
|
||||
walkdir = "2.2"
|
||||
rust-crypto = "0.2"
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3.0"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
use storage::Version;
|
||||
use walkdir::DirEntry;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
|
@ -28,11 +29,15 @@ impl<'a> Engine<'a> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn file_version(&self, path: &Path) -> u64 {
|
||||
0
|
||||
pub fn file_version(&self, path: &Path) -> Version {
|
||||
Version(0)
|
||||
}
|
||||
|
||||
fn process_entry(&self, entry: &DirEntry) -> Result<(), io::Error> {
|
||||
// TODO: remember entry in index
|
||||
|
||||
// TODO: store file data
|
||||
|
||||
if entry.file_type().is_dir() {
|
||||
fs::create_dir(self.repository_path.join(entry.file_name()))?;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
extern crate core;
|
||||
extern crate crypto;
|
||||
#[cfg(test)]
|
||||
extern crate dir_diff;
|
||||
#[cfg(test)]
|
||||
|
@ -7,3 +8,5 @@ extern crate walkdir;
|
|||
|
||||
pub mod backup;
|
||||
pub mod restore;
|
||||
|
||||
mod storage;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use std::fs;
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
use storage::Version;
|
||||
use walkdir::DirEntry;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
|
@ -27,10 +28,10 @@ impl<'a> Engine<'a> {
|
|||
}
|
||||
|
||||
fn restore(&self, what: WhatToRestore) -> Result<(), io::Error> {
|
||||
self.restore_as_of_version(what, 0)
|
||||
self.restore_as_of_version(what, Version(0))
|
||||
}
|
||||
|
||||
pub fn restore_as_of_version(&self, what: WhatToRestore, version: u64) -> Result<(), io::Error> {
|
||||
pub fn restore_as_of_version(&self, what: WhatToRestore, version: Version) -> Result<(), io::Error> {
|
||||
let walker = WalkDir::new(self.repository_path);
|
||||
for maybe_entry in walker {
|
||||
match maybe_entry {
|
||||
|
|
42
src/storage.rs
Normal file
42
src/storage.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use std::cmp::Ordering;
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Copy, Clone, PartialOrd, PartialEq)]
|
||||
pub struct Version(pub u64);
|
||||
|
||||
struct Index;
|
||||
|
||||
impl Index {
|
||||
fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
|
||||
fn store(&mut self, path: &Path, hash: &[u8]) -> Version {
|
||||
Version(0)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod should {
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn support_file_versions() {
|
||||
// put path and hash into index -> v0
|
||||
// put same path different hash -> v1
|
||||
// query for v0, v1
|
||||
let mut index = Index::new();
|
||||
let v1 = index.store(Path::new("/some/path"), "some hash".as_bytes());
|
||||
let v2 = index.store(Path::new("/some/path"), "some other hash".as_bytes());
|
||||
|
||||
assert!(v2 > v1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn support_deduplication() {
|
||||
// put path and hash into index
|
||||
// put same hash, different path
|
||||
// should get same storage paths
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue