From 12b8f8f33105ca340700fd63ff004a3773b0fb47 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 2 Jul 2016 17:52:12 +0200 Subject: [PATCH] Move storification of StoreId object to new StoreId::storified() func --- libimagstore/src/store.rs | 24 ++++++++---------------- libimagstore/src/storeid.rs | 12 ++++++++++++ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 82dd1a2e..1d7a3931 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -317,17 +317,9 @@ impl Store { self.configuration.as_ref() } - fn storify_id(&self, id: StoreId) -> StoreId { - debug!("Create new store id out of: {:?} and {:?}", self.location, id); - let mut new_id = self.location.clone(); - new_id.push(id); - debug!("Created: '{:?}'", new_id); - StoreId::from(new_id) - } - /// Creates the Entry at the given location (inside the entry) pub fn create<'a, S: IntoStoreId>(&'a self, id: S) -> Result> { - let id = self.storify_id(id.into_storeid()); + let id = id.into_storeid().storified(self); if let Err(e) = self.execute_hooks_for_id(self.pre_create_aspects.clone(), &id) { if e.is_aborting() { return Err(e) @@ -365,7 +357,7 @@ impl Store { /// Implicitely creates a entry in the store if there is no entry with the id `id`. For a /// non-implicitely-create look at `Store::get`. pub fn retrieve<'a, S: IntoStoreId>(&'a self, id: S) -> Result> { - let id = self.storify_id(id.into_storeid()); + let id = id.into_storeid().storified(self); if let Err(e) = self.execute_hooks_for_id(self.pre_retrieve_aspects.clone(), &id) { if e.is_aborting() { return Err(e) @@ -398,7 +390,7 @@ impl Store { /// /// This executes the {pre,post}_retrieve_aspects hooks. pub fn get<'a, S: IntoStoreId + Clone>(&'a self, id: S) -> Result>> { - if !self.storify_id(id.clone().into_storeid()).exists() { + if !id.clone().into_storeid().storified(self).exists() { debug!("Does not exist: {:?}", id.clone().into_storeid()); return Ok(None); } @@ -520,7 +512,7 @@ impl Store { /// Retrieve a copy of a given entry, this cannot be used to mutate /// the one on disk pub fn retrieve_copy(&self, id: S) -> Result { - let id = self.storify_id(id.into_storeid()); + let id = id.into_storeid().storified(self); let entries = match self.entries.write() { Err(_) => { return Err(SE::new(SEK::LockPoisoned, None)) @@ -539,7 +531,7 @@ impl Store { /// Delete an entry pub fn delete(&self, id: S) -> Result<()> { - let id = self.storify_id(id.into_storeid()); + let id = id.into_storeid().storified(self); if let Err(e) = self.execute_hooks_for_id(self.pre_delete_aspects.clone(), &id) { if e.is_aborting() { return Err(e) @@ -593,7 +585,7 @@ impl Store { use std::fs::copy; use std::fs::remove_file; - let new_id = self.storify_id(new_id); + let new_id = new_id.storified(self); let hsmap = self.entries.write(); if hsmap.is_err() { return Err(SE::new(SEK::LockPoisoned, None)).map_err_into(SEK::MoveCallError) @@ -622,8 +614,8 @@ impl Store { pub fn move_by_id(&self, old_id: StoreId, new_id: StoreId) -> Result<()> { use std::fs::rename; - let new_id = self.storify_id(new_id); - let old_id = self.storify_id(old_id); + let new_id = new_id.storified(self); + let old_id = old_id.storified(self); if let Err(e) = self.execute_hooks_for_id(self.pre_move_aspects.clone(), &old_id) { if e.is_aborting() { diff --git a/libimagstore/src/storeid.rs b/libimagstore/src/storeid.rs index 147b80cb..48f8b834 100644 --- a/libimagstore/src/storeid.rs +++ b/libimagstore/src/storeid.rs @@ -16,6 +16,18 @@ use store::Store; #[derive(Debug, Clone, PartialEq, Hash, Eq, PartialOrd, Ord)] pub struct StoreId(PathBuf); +impl StoreId { + + pub fn storified(self, store: &Store) -> StoreId { + debug!("Create new store id out of: {:?} and {:?}", store.path(), self); + let mut new_id = store.path().clone(); + new_id.push(self); + debug!("Created: '{:?}'", new_id); + StoreId::from(new_id) + } + +} + impl Into for StoreId { fn into(self) -> PathBuf {