From bc152b6609ece282e8f1e0ad671df58fcbac2f95 Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Wed, 22 Mar 2017 14:10:42 +0100 Subject: [PATCH] Fixes --- src/bundledb/db.rs | 7 ++++++- src/cli/args.rs | 5 ++++- src/cli/mod.rs | 4 ++-- src/repository/mod.rs | 6 +++++- src/repository/vacuum.rs | 2 +- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/bundledb/db.rs b/src/bundledb/db.rs index 7190706..4b5d69b 100644 --- a/src/bundledb/db.rs +++ b/src/bundledb/db.rs @@ -145,6 +145,11 @@ impl BundleDb { Ok((new, gone)) } + pub fn save_cache(&self) -> Result<(), BundleDbError> { + let bundles: Vec<_> = self.remote_bundles.values().cloned().collect(); + Ok(try!(StoredBundle::save_list_to(&bundles, &self.remote_cache_path))) + } + pub fn update_cache(&mut self, new: &[StoredBundle], gone: &[StoredBundle]) -> Result<(), BundleDbError> { for bundle in new { if bundle.info.mode == BundleMode::Meta { @@ -237,7 +242,7 @@ impl BundleDb { } let (folder, filename) = bundle_path(&id, self.remote_path.clone(), self.remote_bundles.len()); try!(fs::create_dir_all(&folder).context(&folder as &Path)); - let bundle = try!(bundle.copy_to(folder.join(filename))); + let bundle = try!(bundle.move_to(folder.join(filename))); self.remote_bundles.insert(bundle.id(), bundle.clone()); Ok(bundle.info) } diff --git a/src/cli/args.rs b/src/cli/args.rs index a51942c..71aaa37 100644 --- a/src/cli/args.rs +++ b/src/cli/args.rs @@ -11,7 +11,8 @@ pub enum Arguments { chunker: ChunkerType, compression: Option, encryption: bool, - hash: HashMethod + hash: HashMethod, + remote: String }, Backup { repo_path: String, @@ -200,6 +201,7 @@ pub fn parse() -> Arguments { (@arg compression: --compression -c +takes_value "compression to use [default: brotli/3]") (@arg encryption: --encryption -e "generate a keypair and enable encryption") (@arg hash: --hash +takes_value "hash method to use [default: blake2]") + (@arg remote: --remote -r +takes_value +required "path to the mounted remote storage") (@arg REPO: +required "path of the repository") ) (@subcommand backup => @@ -299,6 +301,7 @@ pub fn parse() -> Arguments { encryption: args.is_present("encryption"), hash: parse_hash(args.value_of("hash").unwrap_or(DEFAULT_HASH)), repo_path: repository.to_string(), + remote: args.value_of("remote").unwrap().to_string() } } if let Some(args) = args.subcommand_matches("backup") { diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 40a104d..53a1e9c 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -136,14 +136,14 @@ pub fn run() { exit(-1) } match args::parse() { - Arguments::Init{repo_path, bundle_size, chunker, compression, encryption, hash} => { + Arguments::Init{repo_path, bundle_size, chunker, compression, encryption, hash, remote} => { let mut repo = Repository::create(repo_path, Config { bundle_size: bundle_size, chunker: chunker, compression: compression, encryption: None, hash: hash - }).unwrap(); + }, remote).unwrap(); if encryption { let (public, secret) = gen_keypair(); println!("Public key: {}", to_hex(&public[..])); diff --git a/src/repository/mod.rs b/src/repository/mod.rs index 3783d4a..1c9b989 100644 --- a/src/repository/mod.rs +++ b/src/repository/mod.rs @@ -15,6 +15,7 @@ use std::cmp::max; use std::path::{PathBuf, Path}; use std::fs; use std::sync::{Arc, Mutex}; +use std::os::unix::fs::symlink; pub use self::error::RepositoryError; pub use self::config::Config; @@ -41,11 +42,12 @@ pub struct Repository { impl Repository { - pub fn create>(path: P, config: Config) -> Result { + pub fn create, R: AsRef>(path: P, config: Config, remote: R) -> Result { let path = path.as_ref().to_owned(); try!(fs::create_dir(&path)); try!(fs::create_dir(path.join("keys"))); let crypto = Arc::new(Mutex::new(try!(Crypto::open(path.join("keys"))))); + try!(symlink(remote, path.join("remote"))); let bundles = try!(BundleDb::create( path.join("remote/bundles"), path.join("bundles"), @@ -101,6 +103,7 @@ impl Repository { for bundle in gone { try!(repo.remove_gone_remote_bundle(bundle)) } + try!(repo.save_bundle_map()); repo.next_meta_bundle = repo.next_free_bundle_id(); repo.next_content_bundle = repo.next_free_bundle_id(); Ok(repo) @@ -162,6 +165,7 @@ impl Repository { self.next_meta_bundle = self.next_free_bundle_id() } try!(self.save_bundle_map()); + try!(self.bundles.save_cache()); Ok(()) } diff --git a/src/repository/vacuum.rs b/src/repository/vacuum.rs index 09efdef..52c9722 100644 --- a/src/repository/vacuum.rs +++ b/src/repository/vacuum.rs @@ -138,7 +138,7 @@ impl Repository { }; let entry = self.index.get_entry(pos).unwrap(); if rewrite_bundles.contains(&entry.data.bundle) { - panic!("Removed bundle is still referenced from index"); + panic!("Removed bundle is still referenced in index"); } pos += 1; }