aboutsummaryrefslogtreecommitdiff
path: root/lockchain-files
diff options
context:
space:
mode:
authorKatharina Fey <kookie@spacekookie.de>2018-05-09 00:26:05 +0200
committerKatharina Fey <kookie@spacekookie.de>2018-05-09 00:26:05 +0200
commit659eaa9ff296ae3e03362593ee756cbe6d1f42ed (patch)
tree9489e5d205fb4fc0975cd21e41357ad3c2f80af1 /lockchain-files
parent2d95fbfce49cbb3decbe819aefb9bae1491d1469 (diff)
Bumping version on core and crypto
Diffstat (limited to 'lockchain-files')
-rw-r--r--lockchain-files/Cargo.toml8
-rw-r--r--lockchain-files/src/fs.rs47
-rw-r--r--lockchain-files/src/lib.rs80
-rw-r--r--lockchain-files/src/vault.rs0
4 files changed, 128 insertions, 7 deletions
diff --git a/lockchain-files/Cargo.toml b/lockchain-files/Cargo.toml
index 8b6b828..9a5fd9f 100644
--- a/lockchain-files/Cargo.toml
+++ b/lockchain-files/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "lockchain-files"
description = "Filesystem storage backend for lockchain vaults"
-version = "0.0.0"
+version = "0.1.0"
authors = ["Katharina Fey <kookie@spacekookie.de>"]
documentation = "https://docs.rs/lockchain-files"
@@ -10,4 +10,8 @@ readme = "README.md"
license = "MIT/X11 OR Apache-2.0"
[dependencies]
-lockchain-core = ">=0.3.2"
+lockchain-core = { version = ">=0.5.0-alpha", path = "../lockchain-core" }
+
+serde = "1.0"
+serde_json = "1.0"
+serde_derive = "1.0" \ No newline at end of file
diff --git a/lockchain-files/src/fs.rs b/lockchain-files/src/fs.rs
new file mode 100644
index 0000000..52d7729
--- /dev/null
+++ b/lockchain-files/src/fs.rs
@@ -0,0 +1,47 @@
+//! Utility module which handles filesystem writes
+
+use std::path::PathBuf;
+use std::fs::{self, OpenOptions};
+use lcc::traits::AutoEncoder;
+
+use lcc::Record;
+
+pub struct Filesystem {
+ name: String,
+ path: String,
+ root: PathBuf,
+}
+
+pub enum FileType<T> {
+ Record(T),
+ Metadata(T),
+ Checksum(T)
+}
+
+impl Filesystem {
+ pub fn create(path: &str, name: &str) -> Filesystem {
+ let mut buffer = PathBuf::new();
+ buffer.push(path);
+ buffer.push(format!("{}.vault", name));
+
+ Filesystem {
+ name: name.to_owned(),
+ path: path.to_owned(),
+ root: buffer,
+ }
+ }
+
+ /// Create required directories
+ pub fn scaffold(&self) -> Option<()> {
+ fs::create_dir_all(&self.root).ok()?;
+ fs::create_dir(&self.root.join("records")).ok()?;
+ fs::create_dir(&self.root.join("metadata")).ok()?;
+ fs::create_dir(&self.root.join("checksums")).ok()?;
+ Some(())
+ }
+
+ /// Load all files of a certain type into a Vec<String>
+ pub fn fetch<T: AutoEncoder>(types: FileType<T>) -> Vec<T> {
+ unimplemented!()
+ }
+}
diff --git a/lockchain-files/src/lib.rs b/lockchain-files/src/lib.rs
index 31e1bb2..90109ac 100644
--- a/lockchain-files/src/lib.rs
+++ b/lockchain-files/src/lib.rs
@@ -1,7 +1,77 @@
-#[cfg(test)]
-mod tests {
- #[test]
- fn it_works() {
- assert_eq!(2 + 2, 4);
+//! A module that enables file management for vaults
+//!
+//!
+#![feature(non_modrs_mods)]
+
+extern crate serde;
+#[macro_use]
+extern crate serde_derive;
+extern crate serde_json;
+
+extern crate lockchain_core as lcc;
+
+use lcc::traits::{Body, Vault};
+use lcc::{Payload, Record};
+use std::collections::HashMap;
+
+mod fs;
+use fs::Filesystem;
+
+/// Represents a vault on disk
+pub struct DataVault<T: Body> {
+ records: HashMap<String, Record<T>>,
+ fs: Filesystem,
+}
+
+impl<T: Body> DataVault<T> {
+ /// Small utility function to setup file structure
+ fn initialize(self) -> Self {
+ self.fs.scaffold();
+ self
+ }
+}
+
+impl<T: Body> Vault<T> for DataVault<T> {
+ fn new(name: &str, location: &str) -> Self {
+ Self {
+ records: HashMap::new(),
+ fs: Filesystem::create(location, name),
+ }.initialize()
+ }
+
+ fn fetch(&mut self) {
+ unimplemented!()
+ }
+
+ fn pull(&mut self, name: &str) {
+ unimplemented!()
+ }
+
+ fn sync(&mut self) {
+ unimplemented!()
+ }
+
+ fn get_record(&self, name: &str) -> Option<&Record<T>> {
+ unimplemented!()
+ }
+
+ fn contains(&self, name: &str) -> bool {
+ unimplemented!()
+ }
+
+ fn add_record(&mut self, key: &str, category: &str, tags: Vec<&str>) {
+ unimplemented!()
+ }
+
+ fn delete_record(&mut self, record: &str) -> Option<Record<T>> {
+ unimplemented!()
+ }
+
+ fn add_data(&mut self, record: &str, key: &str, data: Payload) -> Option<()> {
+ unimplemented!()
+ }
+
+ fn get_data(&self, record: &str, key: &str) -> Option<&Payload> {
+ unimplemented!()
}
}
diff --git a/lockchain-files/src/vault.rs b/lockchain-files/src/vault.rs
deleted file mode 100644
index e69de29..0000000
--- a/lockchain-files/src/vault.rs
+++ /dev/null