diff options
author | Katharina Fey <kookie@spacekookie.de> | 2018-06-12 00:41:19 +0200 |
---|---|---|
committer | Katharina Fey <kookie@spacekookie.de> | 2018-06-12 00:41:19 +0200 |
commit | df6f9365f80b836b18548b4a33b50a4abe94ff38 (patch) | |
tree | 3d7ec7ef4583b4085a396e70105d8d52c451a388 | |
parent | 5a5d1606d481eb1a78d5dc4ce9626d26cf6f9e4a (diff) |
Fixing an issue in the metadomain insert function and fixing some file sync issues
-rw-r--r-- | lockchain-core/src/meta.rs | 6 | ||||
-rw-r--r-- | lockchain-files/src/fs.rs | 16 | ||||
-rw-r--r-- | lockchain-files/src/lib.rs | 3 |
3 files changed, 21 insertions, 4 deletions
diff --git a/lockchain-core/src/meta.rs b/lockchain-core/src/meta.rs index fa7fa81..8973b7d 100644 --- a/lockchain-core/src/meta.rs +++ b/lockchain-core/src/meta.rs @@ -25,7 +25,7 @@ use traits::{AutoEncoder, Body}; /// /// It implements a series of traits which means it's possible to easily /// interact with to store data. -#[derive(Serialize, Deserialize)] +#[derive(Debug, Serialize, Deserialize)] pub struct MetaDomain { /// The name of this meta domain name: String, @@ -63,7 +63,9 @@ impl Body for MetaDomain { } fn set_field(&mut self, key: &str, value: Payload) -> Option<()> { - self.body.insert(key.into(), value).map(|_| ()) + self.body + .insert(key.into(), value) + .map_or(Some(()), |_| Some(())) } /// Not implemented, always returns None diff --git a/lockchain-files/src/fs.rs b/lockchain-files/src/fs.rs index 1112733..8f61dfb 100644 --- a/lockchain-files/src/fs.rs +++ b/lockchain-files/src/fs.rs @@ -9,6 +9,7 @@ use std::{ fs::{self, File, OpenOptions as OO}, path::PathBuf, }; +#[derive(Debug)] pub struct Filesystem { name: String, path: String, @@ -90,10 +91,21 @@ impl Filesystem { { data.into_iter() .map(|(k, v)| (k, v.encode().ok())) - .map(|(k, v)| (self.root.join(format!("{}.{}", k, file_ending!(types))), v)) + .map(|(k, v)| { + ( + match types { + FileType::Record => self.root.join("records"), + FileType::Metadata => self.root.join("metadata"), + _ => self.root.join("."), + }.join(format!("{}.{}", k, file_ending!(types))), + v, + ) + }) .filter(|(_, v)| v.is_some()) .map(|(k, v)| (k, v.unwrap())) - .map(|(path, data): (PathBuf, String)| (OO::new().write(true).open(path), data)) + .map(|(path, data): (PathBuf, String)| { + (OO::new().create(true).write(true).open(path), data) + }) .filter(|(path, _)| path.is_ok()) .map(|(file, data)| (file.unwrap(), data)) .for_each(|(mut file, data)| { diff --git a/lockchain-files/src/lib.rs b/lockchain-files/src/lib.rs index 5073aed..c86ff2e 100644 --- a/lockchain-files/src/lib.rs +++ b/lockchain-files/src/lib.rs @@ -8,11 +8,13 @@ extern crate lockchain_core as lcc; use lcc::traits::{Body, Vault}; use lcc::{MetaDomain, Payload, Record}; use std::collections::HashMap; +use std::fmt::Debug; mod fs; use fs::{FileType, Filesystem}; /// Represents a vault on disk +#[derive(Debug)] pub struct DataVault<T: Body> { records: HashMap<String, Record<T>>, metadata: HashMap<String, MetaDomain>, @@ -70,6 +72,7 @@ impl<T: Body> Vault<T> for DataVault<T> { } fn sync(&mut self) { + println!("{:#?}", self.metadata); self.fs .sync::<Record<T>>(&self.records, FileType::Record) .unwrap(); |