Merge pull request #145 from neithernut/fix-store-retrieve
Fix Store::retrieve()
This commit is contained in:
commit
3b51328aa7
1 changed files with 11 additions and 9 deletions
|
@ -142,15 +142,17 @@ impl Store {
|
||||||
/// Borrow a given Entry. When the `FileLockEntry` is either `update`d or
|
/// Borrow a given Entry. When the `FileLockEntry` is either `update`d or
|
||||||
/// dropped, the new Entry is written to disk
|
/// dropped, the new Entry is written to disk
|
||||||
pub fn retrieve<'a>(&'a self, id: StoreId) -> Result<FileLockEntry<'a>> {
|
pub fn retrieve<'a>(&'a self, id: StoreId) -> Result<FileLockEntry<'a>> {
|
||||||
let hsmap = self.entries.write();
|
self.entries
|
||||||
if hsmap.is_err() {
|
.write()
|
||||||
return Err(StoreError::new(StoreErrorKind::LockPoisoned, None))
|
.map_err(|_| StoreError::new(StoreErrorKind::LockPoisoned, None))
|
||||||
}
|
.and_then(|mut es| {
|
||||||
hsmap.unwrap().get_mut(&id)
|
let mut se = es.entry(id.clone()).or_insert_with(|| StoreEntry::new(id.clone()));
|
||||||
.ok_or(StoreError::new(StoreErrorKind::IdNotFound, None))
|
let entry = se.get_entry();
|
||||||
.and_then(|store_entry| store_entry.get_entry())
|
se.status = StoreEntryStatus::Borrowed;
|
||||||
.and_then(|entry| Ok(FileLockEntry::new(self, entry, id)))
|
entry
|
||||||
}
|
})
|
||||||
|
.map(|e| FileLockEntry::new(self, e, id))
|
||||||
|
}
|
||||||
|
|
||||||
/// Iterate over all StoreIds for one module name
|
/// Iterate over all StoreIds for one module name
|
||||||
pub fn retrieve_for_module(&self, mod_name: &str) -> StoreIdIterator {
|
pub fn retrieve_for_module(&self, mod_name: &str) -> StoreIdIterator {
|
||||||
|
|
Loading…
Reference in a new issue