Merge pull request #910 from matthiasbeyer/libimagstore/non-consuming-update

Libimagstore/non consuming update
This commit is contained in:
Matthias Beyer 2017-03-08 15:30:19 +01:00 committed by GitHub
commit 5d4ef8ed7f
2 changed files with 14 additions and 12 deletions

View file

@ -426,7 +426,8 @@ methods!(
store <- itself wrapped inside STORE_WRAPPER, store <- itself wrapped inside STORE_WRAPPER,
real_fle <- fetch fle, real_fle <- fetch fle,
operation { 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); trace_error(&e);
VM::raise(Class::from_existing("RImagStoreWriteError"), e.description()); VM::raise(Class::from_existing("RImagStoreWriteError"), e.description());
} }

View file

@ -606,8 +606,8 @@ impl Store {
/// ///
/// See `Store::_update()`. /// See `Store::_update()`.
/// ///
pub fn update<'a>(&'a self, mut entry: FileLockEntry<'a>) -> Result<()> { pub fn update<'a>(&'a self, entry: &mut FileLockEntry<'a>) -> Result<()> {
self._update(&mut entry, false).map_err_into(SEK::UpdateCallError) self._update(entry, false).map_err_into(SEK::UpdateCallError)
} }
/// Internal method to write to the filesystem store. /// Internal method to write to the filesystem store.
@ -2007,7 +2007,8 @@ aspect = "test"
{ {
println!("Getting {:?} -> Some -> updating", pb_moved); println!("Getting {:?} -> Some -> updating", pb_moved);
assert!(match store.get(pb_moved.clone()).map_err(|e| println!("ERROR GETTING: {:?}", e)) { 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, _ => false,
}); });
} }
@ -2110,9 +2111,9 @@ aspect = "test"
fn test_pre_update_error() { fn test_pre_update_error() {
let storeid = StoreId::new_baseless(PathBuf::from("test_pre_update_error")).unwrap(); let storeid = StoreId::new_baseless(PathBuf::from("test_pre_update_error")).unwrap();
let store = get_store_with_aborting_hook_at_pos(HP::PreUpdate); 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] #[test]
@ -2155,11 +2156,11 @@ aspect = "test"
fn test_post_update_error() { fn test_post_update_error() {
let store = get_store_with_aborting_hook_at_pos(HP::PostUpdate); let store = get_store_with_aborting_hook_at_pos(HP::PostUpdate);
let pb = StoreId::new_baseless(PathBuf::from("test_post_update_error")).unwrap(); 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()); let pb = pb.with_base(store.path().clone());
assert!(store.entries.read().unwrap().get(&pb).is_some()); 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 { fn get_store_with_allowed_error_hook_at_pos(pos: HP) -> Store {
@ -2196,9 +2197,9 @@ aspect = "test"
fn test_pre_update_allowed_error() { fn test_pre_update_allowed_error() {
let storeid = StoreId::new_baseless(PathBuf::from("test_pre_update_allowed_error")).unwrap(); 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 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] #[test]
@ -2241,11 +2242,11 @@ aspect = "test"
fn test_post_update_allowed_error() { fn test_post_update_allowed_error() {
let store = get_store_with_allowed_error_hook_at_pos(HP::PostUpdate); 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 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()); let pb = pb.with_base(store.path().clone());
assert!(store.entries.read().unwrap().get(&pb).is_some()); assert!(store.entries.read().unwrap().get(&pb).is_some());
assert!(store.update(fle).is_ok()); assert!(store.update(&mut fle).is_ok());
} }
} }