diff --git a/Cargo.toml b/Cargo.toml index a37f332..bd9482b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ name = "bakare" version = "0.1.0" authors = ["Cyryl PÅ‚otnicki "] +edition = "2018" [dependencies] walkdir = "2.2" diff --git a/src/backup.rs b/src/backup.rs index 72078c9..c76a5e7 100644 --- a/src/backup.rs +++ b/src/backup.rs @@ -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> { diff --git a/src/restore.rs b/src/restore.rs index 77b3df1..eef0f67 100644 --- a/src/restore.rs +++ b/src/restore.rs @@ -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> { diff --git a/src/storage.rs b/src/storage.rs index 5cf7f03..279b186 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -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| { diff --git a/tests/system_tests.rs b/tests/system_tests.rs index bcb60cf..0692d9d 100644 --- a/tests/system_tests.rs +++ b/tests/system_tests.rs @@ -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;