Random bundle name

pull/10/head
Dennis Schwerdel 2017-04-02 20:45:35 +02:00 committed by Dennis Schwerdel
parent 727f59b2d3
commit f6862aa669
6 changed files with 10 additions and 3 deletions

1
Cargo.lock generated
View File

@ -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)",

View File

@ -25,6 +25,7 @@ filetime = "0.1"
regex = "0.2"
fuse = "0.3"
lazy_static = "0.2"
rand = "0.3"
time = "*"
libc = "*"

View File

@ -106,7 +106,6 @@ Recommended: Brotli/2-7
### Formats
- Bundles
- Encrypted bundle header
- Random bundle name
- Metadata
- Arbitrarily nested chunk lists

View File

@ -255,11 +255,11 @@ impl BundleDb {
#[inline]
pub fn add_bundle(&mut self, bundle: BundleWriter) -> Result<BundleInfo, BundleDbError> {
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());

View File

@ -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 {

View File

@ -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;