introduce version enum

This commit is contained in:
Cyryl Płotnicki 2018-12-22 11:31:27 +00:00
parent d284f7d2f3
commit 41792ae473
5 changed files with 15 additions and 11 deletions

View file

@ -2,6 +2,7 @@
name = "bakare"
version = "0.1.0"
authors = ["Cyryl Płotnicki <cyplo@cyplo.net>"]
edition = "2018"
[dependencies]
walkdir = "2.2"

View file

@ -1,7 +1,7 @@
use crate::storage::Version;
use std::fs;
use std::io;
use std::path::Path;
use storage::Version;
use walkdir::DirEntry;
use walkdir::WalkDir;
@ -30,7 +30,7 @@ impl<'a> Engine<'a> {
}
pub fn file_version(&self, path: &Path) -> Version {
Version(0)
Version::Newest
}
fn process_entry(&self, entry: &DirEntry) -> Result<(), io::Error> {

View file

@ -1,7 +1,7 @@
use crate::storage::Version;
use std::fs;
use std::io;
use std::path::Path;
use storage::Version;
use walkdir::DirEntry;
use walkdir::WalkDir;
@ -28,7 +28,7 @@ impl<'a> Engine<'a> {
}
fn restore(&self, what: WhatToRestore) -> Result<(), io::Error> {
self.restore_as_of_version(what, Version(0))
self.restore_as_of_version(what, Version::Newest)
}
pub fn restore_as_of_version(&self, what: WhatToRestore, version: Version) -> Result<(), io::Error> {

View file

@ -2,11 +2,17 @@ use std::collections::HashMap;
use std::collections::HashSet;
#[derive(Copy, Clone, Debug, PartialOrd, PartialEq)]
pub struct Version(pub u64);
pub enum Version {
Newest,
Specific(u64),
}
impl Version {
fn next(self) -> Self {
Version(self.0 + 1)
match self {
Version::Newest => Version::Newest,
Version::Specific(old) => Version::Specific(old + 1),
}
}
}
@ -44,7 +50,7 @@ impl<'a> Index<'a> {
self.file_paths.get(source_path).map_or_else(
|| IndexPathEntry {
hash,
version: Version(0),
version: Version::Newest,
storage_path: format!("{:X?}", hash.0),
},
|old_entry| {

View file

@ -1,10 +1,7 @@
extern crate bakare;
extern crate dir_diff;
extern crate tempfile;
use bakare::backup;
use bakare::restore;
use bakare::restore::WhatToRestore::SpecificPath;
use dir_diff::is_different;
use std::fs::File;
use std::io::Error;