aboutsummaryrefslogtreecommitdiff
path: root/lockchain-files/src
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2018-09-16 11:03:38 +0100
committerKatharina Fey <kookie@spacekookie.de>2018-09-16 11:03:38 +0100
commit39a9b4ab3f1ab8a4c79962e1de78204faaf10abe (patch)
tree9cec5f02cc8d227eeb0a2c81b3d6761ffd6aed65 /lockchain-files/src
parentb257bdaefe633ebb72590aac2b7f504af51ba23e (diff)
Only relying on the `UserStore` `AutoEncoder` impl for serialisation
Diffstat (limited to 'lockchain-files/src')
-rw-r--r--lockchain-files/src/fs/mod.rs4
-rw-r--r--lockchain-files/src/fs/primitive.rs2
-rw-r--r--lockchain-files/src/userstore.rs16
3 files changed, 20 insertions, 2 deletions
diff --git a/lockchain-files/src/fs/mod.rs b/lockchain-files/src/fs/mod.rs
index eed860d..7820925 100644
--- a/lockchain-files/src/fs/mod.rs
+++ b/lockchain-files/src/fs/mod.rs
@@ -88,11 +88,11 @@ impl Filesystem {
pub fn sync_vault<T: Body>(&self, vault: &FileVault<T>) -> Result<(), io::Error> {
vault.config.save(&self.root)?;
-
unimplemented!()
}
/// Respond to a sync request
+ #[deprecated]
pub fn sync<T>(&self, data: &HashMap<String, T>, types: FileType) -> Result<(), Box<Error>>
where
T: AutoEncoder,
@@ -122,4 +122,6 @@ impl Filesystem {
// Ok(())
}
+
+ /************* Private utility functions*************/
}
diff --git a/lockchain-files/src/fs/primitive.rs b/lockchain-files/src/fs/primitive.rs
index c5e13a3..d567a28 100644
--- a/lockchain-files/src/fs/primitive.rs
+++ b/lockchain-files/src/fs/primitive.rs
@@ -47,7 +47,7 @@ fn type_path(tt: FileType, root: &PathBuf) -> PathBuf {
path
}
-pub fn write_file(tt: FileType, root: PathBuf, name: &str, contents: Vec<u8>) -> Result<()> {
+pub(crate) fn write_file(tt: FileType, root: PathBuf, name: &str, contents: Vec<u8>) -> Result<()> {
let file_name = format!("{}.{}", name, file_ending!(&tt));
let mut path = type_path(tt, &root);
path.push(file_name);
diff --git a/lockchain-files/src/userstore.rs b/lockchain-files/src/userstore.rs
index f7bfccd..4c4ff43 100644
--- a/lockchain-files/src/userstore.rs
+++ b/lockchain-files/src/userstore.rs
@@ -1,4 +1,20 @@
//! Implements serialization, desrialization for UserStore
+use lcc::{errors::DataError, traits::AutoEncoder, users::UserStore};
+pub trait DiskMirror {
+ fn to_disk(&self) -> Vec<u8>;
+ fn from_disk(Vec<u8>) -> Result<Box<Self>, DataError>;
+}
+impl DiskMirror for UserStore {
+ fn to_disk(&self) -> Vec<u8> {
+ self.encode().unwrap().into_bytes()
+ }
+
+ fn from_disk(vec: Vec<u8>) -> Result<Box<Self>, DataError> {
+ Self::decode(::std::str::from_utf8(vec.as_slice()).map_err(|_| DataError::FailedDecode)?)
+ .map(|s| Box::new(s))
+ .map_err(|_| DataError::FailedDecode)
+ }
+}