Use StoreEntry instead of a tuple

This commit is contained in:
Marcel Müller 2016-01-16 20:30:16 +01:00
parent d4c850ef17
commit 463c182bcc
No known key found for this signature in database
GPG key ID: DD4ED37D0CAC76E2

View file

@ -58,6 +58,25 @@ impl<ISI: IntoStoreId> IntoStoreId for (ISI, ISI) {
} }
} }
struct StoreEntry {
file: File,
entry: Option<Entry>,
}
impl StoreEntry {
fn is_borrowed(&self) -> bool {
self.entry.is_none()
}
fn set_entry(&mut self, entry: Entry) -> Result<()> {
self.entry = Some(entry);
unimplemented!()
}
fn get_entry(&mut self) -> Result<Entry> {
unimplemented!()
}
}
pub struct Store { pub struct Store {
location: PathBuf, location: PathBuf,
@ -69,7 +88,7 @@ pub struct Store {
* *
* Could be optimized for a threadsafe HashMap * Could be optimized for a threadsafe HashMap
*/ */
entries: Arc<RwLock<HashMap<StoreId, (File, Option<Entry>)>>>, entries: Arc<RwLock<HashMap<StoreId, StoreEntry>>>,
} }
impl Store { impl Store {
@ -103,7 +122,7 @@ impl Drop for Store {
*/ */
fn drop(&mut self) { fn drop(&mut self) {
self.entries.write().unwrap() self.entries.write().unwrap()
.iter().map(|f| (f.1).0.unlock()); .iter().map(|f| f.1.file.unlock());
} }
} }
@ -141,8 +160,7 @@ impl<'a> ::std::ops::DerefMut for FileLockEntry<'a> {
impl<'a> Drop for FileLockEntry<'a> { impl<'a> Drop for FileLockEntry<'a> {
fn drop(&mut self) { fn drop(&mut self) {
let mut map = self.store.entries.write().unwrap(); let mut map = self.store.entries.write().unwrap();
let (_, ref mut en) = *map.get_mut(&self.key).unwrap(); map.get_mut(&self.key).unwrap().set_entry(self.entry.clone());
*en = Some(self.entry.clone());
} }
} }