summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2017-03-08 15:30:19 +0100
committerGitHub <noreply@github.com>2017-03-08 15:30:19 +0100
commit5d4ef8ed7f243c73b514378fa9693e92295065cd (patch)
tree2c2e8ddc9cb201953e3d54a6989427a99480bcf9
parent3a0166ba7c301b92cc0ccdbec137a42345963dd9 (diff)
parent89b08d77aa1606bcf5d0c64639c99839f1f7fadb (diff)
downloadimag-5d4ef8ed7f243c73b514378fa9693e92295065cd.zip
imag-5d4ef8ed7f243c73b514378fa9693e92295065cd.tar.gz
Merge pull request #910 from matthiasbeyer/libimagstore/non-consuming-update
Libimagstore/non consuming update
-rw-r--r--libimagruby/src/store.rs3
-rw-r--r--libimagstore/src/store.rs23
2 files changed, 14 insertions, 12 deletions
diff --git a/libimagruby/src/store.rs b/libimagruby/src/store.rs
index 518b42a..193ac66 100644
--- a/libimagruby/src/store.rs
+++ b/libimagruby/src/store.rs
@@ -426,7 +426,8 @@ methods!(
store <- itself wrapped inside STORE_WRAPPER,
real_fle <- fetch fle,
operation {
- if let Err(e) = store.update(real_fle) {
+ let mut real_fle = real_fle; // rebind for mut
+ if let Err(e) = store.update(&mut real_fle) {
trace_error(&e);
VM::raise(Class::from_existing("RImagStoreWriteError"), e.description());
}
diff --git a/libimagstore/src/store.rs b/libimagstore/src/store.rs
index 7ccb074..9bb1aff 100644
--- a/libimagstore/src/store.rs
+++ b/libimagstore/src/store.rs
@@ -606,8 +606,8 @@ impl Store {
///
/// See `Store::_update()`.
///
- pub fn update<'a>(&'a self, mut entry: FileLockEntry<'a>) -> Result<()> {
- self._update(&mut entry, false).map_err_into(SEK::UpdateCallError)
+ pub fn update<'a>(&'a self, entry: &mut FileLockEntry<'a>) -> Result<()> {
+ self._update(entry, false).map_err_into(SEK::UpdateCallError)
}
/// Internal method to write to the filesystem store.
@@ -2007,7 +2007,8 @@ aspect = "test"
{
println!("Getting {:?} -> Some -> updating", pb_moved);
assert!(match store.get(pb_moved.clone()).map_err(|e| println!("ERROR GETTING: {:?}", e)) {
- Ok(Some(fle)) => store.update(fle).map_err(|e| println!("ERROR UPDATING: {:?}", e)).is_ok(),
+ Ok(Some(mut fle)) => store.update(&mut fle)
+ .map_err(|e| println!("ERROR UPDATING: {:?}", e)).is_ok(),
_ => false,
});
}
@@ -2110,9 +2111,9 @@ aspect = "test"
fn test_pre_update_error() {
let storeid = StoreId::new_baseless(PathBuf::from("test_pre_update_error")).unwrap();
let store = get_store_with_aborting_hook_at_pos(HP::PreUpdate);
- let fle = store.create(storeid).unwrap();
+ let mut fle = store.create(storeid).unwrap();
- assert!(store.update(fle).is_err());
+ assert!(store.update(&mut fle).is_err());
}
#[test]
@@ -2155,11 +2156,11 @@ aspect = "test"
fn test_post_update_error() {
let store = get_store_with_aborting_hook_at_pos(HP::PostUpdate);
let pb = StoreId::new_baseless(PathBuf::from("test_post_update_error")).unwrap();
- let fle = store.create(pb.clone()).unwrap();
+ let mut fle = store.create(pb.clone()).unwrap();
let pb = pb.with_base(store.path().clone());
assert!(store.entries.read().unwrap().get(&pb).is_some());
- assert!(store.update(fle).is_err());
+ assert!(store.update(&mut fle).is_err());
}
fn get_store_with_allowed_error_hook_at_pos(pos: HP) -> Store {
@@ -2196,9 +2197,9 @@ aspect = "test"
fn test_pre_update_allowed_error() {
let storeid = StoreId::new_baseless(PathBuf::from("test_pre_update_allowed_error")).unwrap();
let store = get_store_with_allowed_error_hook_at_pos(HP::PreUpdate);
- let fle = store.create(storeid).unwrap();
+ let mut fle = store.create(storeid).unwrap();
- assert!(store.update(fle).is_ok());
+ assert!(store.update(&mut fle).is_ok());
}
#[test]
@@ -2241,11 +2242,11 @@ aspect = "test"
fn test_post_update_allowed_error() {
let store = get_store_with_allowed_error_hook_at_pos(HP::PostUpdate);
let pb = StoreId::new_baseless(PathBuf::from("test_pre_update_allowed_error")).unwrap();
- let fle = store.create(pb.clone()).unwrap();
+ let mut fle = store.create(pb.clone()).unwrap();
let pb = pb.with_base(store.path().clone());
assert!(store.entries.read().unwrap().get(&pb).is_some());
- assert!(store.update(fle).is_ok());
+ assert!(store.update(&mut fle).is_ok());
}
}