diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-10-11 18:28:00 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-10-12 08:53:11 +0200 |
commit | 2cbcfa946c42088063c764325673b94bb7380565 (patch) | |
tree | 075cc25330a8c43aa6ccfffc56df594f9928d585 /libimagstore | |
parent | 17fba2c47f6580fdf462d5a5e486b5375f32411e (diff) | |
parent | dd5928c1b5c301d393b4fce6e02fea2022d8a859 (diff) |
Merge branch 'master' into libimagstore/store-tests-integration
On master, we changed the Store::update() function to do nothing more
than calling Store::_update() and wrapping an error.
On the libimagstore/store-tests branch, we modified the
Store::_update() function to contain an additional flag in the
parameters, whether the File-Lock-Entry internal `precense`-value should
be updated.
This merge commit resolves that conflict.
Diffstat (limited to 'libimagstore')
-rw-r--r-- | libimagstore/src/configuration.rs | 19 | ||||
-rw-r--r-- | libimagstore/src/error.rs | 19 | ||||
-rw-r--r-- | libimagstore/src/file_abstraction.rs | 19 | ||||
-rw-r--r-- | libimagstore/src/hook/accessor.rs | 19 | ||||
-rw-r--r-- | libimagstore/src/hook/aspect.rs | 32 | ||||
-rw-r--r-- | libimagstore/src/hook/error.rs | 19 | ||||
-rw-r--r-- | libimagstore/src/hook/mod.rs | 19 | ||||
-rw-r--r-- | libimagstore/src/hook/position.rs | 19 | ||||
-rw-r--r-- | libimagstore/src/hook/result.rs | 19 | ||||
-rw-r--r-- | libimagstore/src/lib.rs | 19 | ||||
-rw-r--r-- | libimagstore/src/store.rs | 51 | ||||
-rw-r--r-- | libimagstore/src/storeid.rs | 23 |
12 files changed, 250 insertions, 27 deletions
diff --git a/libimagstore/src/configuration.rs b/libimagstore/src/configuration.rs index c450000c..eb9bd196 100644 --- a/libimagstore/src/configuration.rs +++ b/libimagstore/src/configuration.rs @@ -1,3 +1,22 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + use toml::Value; use libimagerror::into::IntoError; diff --git a/libimagstore/src/error.rs b/libimagstore/src/error.rs index 80c10a0c..09ed092f 100644 --- a/libimagstore/src/error.rs +++ b/libimagstore/src/error.rs @@ -1,3 +1,22 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + generate_error_imports!(); use std::convert::From; diff --git a/libimagstore/src/file_abstraction.rs b/libimagstore/src/file_abstraction.rs index dc04d235..de154851 100644 --- a/libimagstore/src/file_abstraction.rs +++ b/libimagstore/src/file_abstraction.rs @@ -1,3 +1,22 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + pub use self::fs::FileAbstraction; // TODO: diff --git a/libimagstore/src/hook/accessor.rs b/libimagstore/src/hook/accessor.rs index b36d1ff4..8bcca25b 100644 --- a/libimagstore/src/hook/accessor.rs +++ b/libimagstore/src/hook/accessor.rs @@ -1,3 +1,22 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + use std::fmt::Debug; use hook::result::HookResult; diff --git a/libimagstore/src/hook/aspect.rs b/libimagstore/src/hook/aspect.rs index bd493122..40dc6085 100644 --- a/libimagstore/src/hook/aspect.rs +++ b/libimagstore/src/hook/aspect.rs @@ -1,3 +1,22 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + use libimagerror::trace::trace_error; use libimagutil::iter::FoldResult; @@ -68,10 +87,6 @@ impl MutableHookDataAccessor for Aspect { fn access_mut(&self, fle: &mut FileLockEntry) -> HookResult<()> { debug!("Checking whether mutable hooks are allowed"); debug!("-> config = {:?}", self.cfg); - if !self.cfg.as_ref().map(|c| c.allow_mutable_hooks()).unwrap_or(false) { - debug!("Apparently mutable hooks are not allowed... failing now."); - return Err(HE::new(HEK::MutableHooksNotAllowed, None)); - } let accessors : Vec<HDA> = self.hooks.iter().map(|h| h.accessor()).collect(); @@ -82,8 +97,15 @@ impl MutableHookDataAccessor for Aspect { accessors.iter().fold_defresult(|accessor| { let res = match accessor { &HDA::StoreIdAccess(ref accessor) => accessor.access(fle.get_location()), - &HDA::MutableAccess(ref accessor) => accessor.access_mut(fle), &HDA::NonMutableAccess(ref accessor) => accessor.access(fle), + &HDA::MutableAccess(ref accessor) => { + if !self.cfg.as_ref().map(|c| c.allow_mutable_hooks()).unwrap_or(false) { + debug!("Apparently mutable hooks are not allowed... failing now."); + return Err(HE::new(HEK::MutableHooksNotAllowed, None)); + } + + accessor.access_mut(fle) + }, }; trace_hook_errors(res) }) diff --git a/libimagstore/src/hook/error.rs b/libimagstore/src/hook/error.rs index a576b931..0d890bf3 100644 --- a/libimagstore/src/hook/error.rs +++ b/libimagstore/src/hook/error.rs @@ -1,3 +1,22 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + use std::default::Default; generate_error_imports!(); diff --git a/libimagstore/src/hook/mod.rs b/libimagstore/src/hook/mod.rs index 43b81de3..5c8e50f2 100644 --- a/libimagstore/src/hook/mod.rs +++ b/libimagstore/src/hook/mod.rs @@ -1,3 +1,22 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + use std::fmt::Debug; use toml::Value; diff --git a/libimagstore/src/hook/position.rs b/libimagstore/src/hook/position.rs index 0ccb563e..8b9f9264 100644 --- a/libimagstore/src/hook/position.rs +++ b/libimagstore/src/hook/position.rs @@ -1,3 +1,22 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + #[derive(Debug, Clone)] pub enum HookPosition { StoreUnload, diff --git a/libimagstore/src/hook/result.rs b/libimagstore/src/hook/result.rs index 11766624..e25c7220 100644 --- a/libimagstore/src/hook/result.rs +++ b/libimagstore/src/hook/result.rs @@ -1,3 +1,22 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + use hook::error::HookError; pub type HookResult<T> = Result<T, HookError>; diff --git a/libimagstore/src/lib.rs b/libimagstore/src/lib.rs index 9268594e..08eb0afa 100644 --- a/libimagstore/src/lib.rs +++ b/libimagstore/src/lib.rs @@ -1,3 +1,22 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + #![deny( non_camel_case_types, non_snake_case, diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs index 49abf928..98187fd9 100644 --- a/libimagstore/src/store.rs +++ b/libimagstore/src/store.rs @@ -1,3 +1,22 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + use std::collections::HashMap; use std::ops::Drop; use std::path::PathBuf; @@ -500,21 +519,7 @@ impl Store { /// Return the `FileLockEntry` and write to disk pub fn update<'a>(&'a self, mut entry: FileLockEntry<'a>) -> Result<()> { - if let Err(e) = self.execute_hooks_for_mut_file(self.pre_update_aspects.clone(), &mut entry) { - return Err(e) - .map_err_into(SEK::PreHookExecuteError) - .map_err_into(SEK::HookExecutionError) - .map_err_into(SEK::UpdateCallError); - } - - if let Err(e) = self._update(&entry, false) { - return Err(e).map_err_into(SEK::UpdateCallError); - } - - self.execute_hooks_for_mut_file(self.post_update_aspects.clone(), &mut entry) - .map_err_into(SEK::PostHookExecuteError) - .map_err_into(SEK::HookExecutionError) - .map_err_into(SEK::UpdateCallError) + self._update(&mut entry, false).map_err_into(SEK::UpdateCallError) } /// Internal method to write to the filesystem store. @@ -522,7 +527,13 @@ impl Store { /// # Assumptions /// This method assumes that entry is dropped _right after_ the call, hence /// it is not public. - fn _update<'a>(&'a self, entry: &FileLockEntry<'a>, modify_presence: bool) -> Result<()> { + fn _update<'a>(&'a self, mut entry: &mut FileLockEntry<'a>, modify_presence: bool) -> Result<()> { + let _ = try!(self.execute_hooks_for_mut_file(self.pre_update_aspects.clone(), &mut entry) + .map_err_into(SEK::PreHookExecuteError) + .map_err_into(SEK::HookExecutionError) + .map_err_into(SEK::UpdateCallError) + ); + let mut hsmap = match self.entries.write() { Err(_) => return Err(SE::new(SEK::LockPoisoned, None)), Ok(e) => e, @@ -541,7 +552,11 @@ impl Store { se.status = StoreEntryStatus::Present; } - Ok(()) + + self.execute_hooks_for_mut_file(self.post_update_aspects.clone(), &mut entry) + .map_err_into(SEK::PostHookExecuteError) + .map_err_into(SEK::HookExecutionError) + .map_err_into(SEK::UpdateCallError) } /// Retrieve a copy of a given entry, this cannot be used to mutate @@ -938,7 +953,7 @@ impl<'a> Drop for FileLockEntry<'a> { impl<'a> Drop for FileLockEntry<'a> { /// This will not silently ignore errors but prints the result of the _update() call for testing fn drop(&mut self) { - println!("Drop Result: {:?}", self.store._update(self, true)); + let _ = self.store._update(self, true).map_err(|e| trace_error(&e)); } } diff --git a/libimagstore/src/storeid.rs b/libimagstore/src/storeid.rs index a5c2c11e..5f979126 100644 --- a/libimagstore/src/storeid.rs +++ b/libimagstore/src/storeid.rs @@ -1,3 +1,22 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + use std::ops::Deref; use std::path::Path; use std::path::PathBuf; @@ -75,10 +94,6 @@ impl StoreId { self.clone().into_pathbuf().map(|pb| pb.exists()).unwrap_or(false) } - pub fn is_file(&self) -> bool { - true - } - pub fn to_str(&self) -> Result<String> { if self.base.is_some() { let mut base = self.base.as_ref().cloned().unwrap(); |