From 3c80180df0b7b3ffc85772f12721244c4c464603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20M=C3=BCller?= Date: Sat, 16 Jan 2016 19:04:15 +0100 Subject: [PATCH] Revert "Make "Store" a trait" This reverts commit 912c84e66347b082c82d91adc6b6da047a5160e4. --- libimagstore/src/fsstore.rs | 83 ----------------------------- libimagstore/src/lib.rs | 2 - libimagstore/src/single_use_lock.rs | 5 -- libimagstore/src/store.rs | 59 +++++++++++++++----- 4 files changed, 46 insertions(+), 103 deletions(-) delete mode 100644 libimagstore/src/fsstore.rs delete mode 100644 libimagstore/src/single_use_lock.rs diff --git a/libimagstore/src/fsstore.rs b/libimagstore/src/fsstore.rs deleted file mode 100644 index c068f7bd..00000000 --- a/libimagstore/src/fsstore.rs +++ /dev/null @@ -1,83 +0,0 @@ -use std::collections::HashMap; -use std::fs::File; -use std::ops::Drop; -use std::path::PathBuf; -use std::result::Result as RResult; -use std::sync::Arc; -use std::sync::RwLock; - -pub use store::Store; -pub use store::Result; -pub use store::FileLockEntry; -pub use entry::Entry; -pub use error::StoreError; - -pub struct FSStore { - location: PathBuf, - - /** - * Internal Path->File cache map - * - * Caches the files, so they remain flock()ed - * - * Could be optimized for a threadsafe HashMap - */ - cache: Arc>>, -} - -impl FSStore { - - pub fn new(location: PathBuf) -> FSStore { - FSStore { - location: location, - cache: Arc::new(RwLock::new(HashMap::new())), - } - } -} - -impl Store for FSStore { - - fn location(&self) -> &PathBuf { - &self.location - } - - fn create(&self, entry: Entry) -> Result<()> { - unimplemented!() - } - - fn retrieve<'a>(&'a self, path: PathBuf) -> Result> { - unimplemented!() - } - - fn retrieve_copy(&self, id : String) -> Result { - unimplemented!() - } - - fn update<'a>(&'a self, entry: FileLockEntry<'a, Self>) -> Result<()> { - unimplemented!() - } - - fn delete(&self, path: PathBuf) -> Result<()> { - unimplemented!() - } - -} - -impl Drop for FSStore { - - /** - * Unlock all files on drop - * - * TODO: Error message when file cannot be unlocked? - */ - fn drop(&mut self) { - use std::ops::DerefMut; - use fs2::FileExt; - - let cache = self.cache.clone(); - cache.write().unwrap().deref_mut().iter().map(|(_, f)| f.unlock()); - } - -} - - diff --git a/libimagstore/src/lib.rs b/libimagstore/src/lib.rs index f4611c02..12c0e09d 100644 --- a/libimagstore/src/lib.rs +++ b/libimagstore/src/lib.rs @@ -4,8 +4,6 @@ extern crate toml; pub mod content; pub mod entry; pub mod error; -pub mod fsstore; pub mod header; -pub mod single_use_lock; pub mod store; diff --git a/libimagstore/src/single_use_lock.rs b/libimagstore/src/single_use_lock.rs deleted file mode 100644 index 57513915..00000000 --- a/libimagstore/src/single_use_lock.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub trait SingleUseLock { - fn access(&self) -> &T; - fn unlock(self) -> T; -} - diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index eaf90d71..fcd36e50 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -11,25 +11,58 @@ pub use error::StoreError; pub type Result = RResult; -pub trait Store : Sized { +pub struct Store { + location: PathBuf, - fn location(&self) -> &PathBuf; + /** + * Internal Path->File cache map + * + * Caches the files, so they remain flock()ed + * + * Could be optimized for a threadsafe HashMap + */ + cache: Arc>>>, +} - fn create(&self, entry: Entry) -> Result<()>; - fn retrieve<'a>(&'a self, path: PathBuf) -> Result>; - fn update<'a>(&'a self, entry: FileLockEntry<'a, Self>) -> Result<()>; - fn retrieve_copy(&self, id : String) -> Result; - fn delete(&self, path: PathBuf) -> Result<()>; +impl Store { + + fn create(&self, entry: Entry) -> Result<()> { + unimplemented!(); + } + fn retrieve<'a>(&'a self, path: PathBuf) -> Result> { + unimplemented!(); + } + fn update<'a>(&'a self, entry: FileLockEntry<'a>) -> Result<()> { + unimplemented!(); + } + fn retrieve_copy(&self, id : String) -> Result { + unimplemented!(); + } + fn delete(&self, path: PathBuf) -> Result<()> { + unimplemented!(); + } +} + +impl Drop for Store { + + /** + * Unlock all files on drop + * + * TODO: Error message when file cannot be unlocked? + */ + fn drop(&mut self) { + self.cache.iter().map(|f| f.unlock()); + } } -pub struct FileLockEntry<'a, S: Store + 'a> { - store: &'a S, +pub struct FileLockEntry<'a> { + store: &'a Store, entry: Entry } -impl<'a, S: Store + 'a> FileLockEntry<'a, S > { - fn new(store: &'a S, entry: Entry) -> FileLockEntry<'a, S> { +impl<'a> FileLockEntry<'a, > { + fn new(store: &'a Store, entry: Entry) -> FileLockEntry<'a> { FileLockEntry { store: store, entry: entry, @@ -37,7 +70,7 @@ impl<'a, S: Store + 'a> FileLockEntry<'a, S > { } } -impl<'a, S: Store + 'a> ::std::ops::Deref for FileLockEntry<'a, S> { +impl<'a> ::std::ops::Deref for FileLockEntry<'a> { type Target = Entry; fn deref(&self) -> &Self::Target { @@ -45,7 +78,7 @@ impl<'a, S: Store + 'a> ::std::ops::Deref for FileLockEntry<'a, S> { } } -impl<'a, S: Store + 'a> ::std::ops::DerefMut for FileLockEntry<'a, S> { +impl<'a> ::std::ops::DerefMut for FileLockEntry<'a> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.entry }