From f6862aa669d1cdd5826a86ed7e302a236e8de59e Mon Sep 17 00:00:00 2001 From: Dennis Schwerdel Date: Sun, 2 Apr 2017 20:45:35 +0200 Subject: [PATCH] Random bundle name --- Cargo.lock | 1 + Cargo.toml | 1 + README.md | 1 - src/bundledb/db.rs | 4 ++-- src/bundledb/mod.rs | 5 +++++ src/main.rs | 1 + 6 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73b4ce4..5a7491c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,6 +16,7 @@ dependencies = [ "murmurhash3 0.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "rmp-serde 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index eeb11ce..84453a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ filetime = "0.1" regex = "0.2" fuse = "0.3" lazy_static = "0.2" +rand = "0.3" time = "*" libc = "*" diff --git a/README.md b/README.md index c8b5886..ed57cf9 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,6 @@ Recommended: Brotli/2-7 ### Formats - Bundles - Encrypted bundle header - - Random bundle name - Metadata - Arbitrarily nested chunk lists diff --git a/src/bundledb/db.rs b/src/bundledb/db.rs index 0f6009a..ab56f22 100644 --- a/src/bundledb/db.rs +++ b/src/bundledb/db.rs @@ -255,11 +255,11 @@ impl BundleDb { #[inline] pub fn add_bundle(&mut self, bundle: BundleWriter) -> Result { let bundle = try!(bundle.finish(&self)); - let id = bundle.id(); + let random_id = BundleId::random(); if bundle.info.mode == BundleMode::Meta { try!(self.copy_remote_bundle_to_cache(&bundle)) } - let (folder, filename) = bundle_path(&id, self.remote_path.clone(), self.remote_bundles.len()); + let (folder, filename) = bundle_path(&random_id, self.remote_path.clone(), self.remote_bundles.len()); try!(fs::create_dir_all(&folder).context(&folder as &Path)); let bundle = try!(bundle.move_to(folder.join(filename))); self.remote_bundles.insert(bundle.id(), bundle.clone()); diff --git a/src/bundledb/mod.rs b/src/bundledb/mod.rs index a585ace..ebe15c2 100644 --- a/src/bundledb/mod.rs +++ b/src/bundledb/mod.rs @@ -12,6 +12,7 @@ use ::prelude::*; use std::fmt; use serde; +use rand; pub static HEADER_STRING: [u8; 7] = *b"zvault\x01"; @@ -39,6 +40,10 @@ impl BundleId { fn to_string(&self) -> String { self.0.to_string() } + + pub fn random() -> Self { + BundleId(Hash{high: rand::random(), low: rand::random()}) + } } impl fmt::Display for BundleId { diff --git a/src/main.rs b/src/main.rs index b15062f..69eafb2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,7 @@ extern crate filetime; extern crate regex; #[macro_use] extern crate lazy_static; extern crate fuse; +extern crate rand; extern crate time; extern crate libc;