fix(auth): fix env being closed when dumping

This commit is contained in:
ad hoc 2022-02-09 13:55:36 +01:00
parent cca65499de
commit 23eba82038
No known key found for this signature in database
GPG key ID: 4F00A782990CC643
2 changed files with 11 additions and 2 deletions

View file

@ -28,11 +28,12 @@ pub struct HeedAuthStore {
env: Arc<Env>,
keys: Database<ByteSlice, SerdeJson<Key>>,
action_keyid_index_expiration: Database<KeyIdActionCodec, SerdeJson<Option<DateTime<Utc>>>>,
should_close_on_drop: bool,
}
impl Drop for HeedAuthStore {
fn drop(&mut self) {
if Arc::strong_count(&self.env) == 1 {
if self.should_close_on_drop && Arc::strong_count(&self.env) == 1 {
self.env.as_ref().clone().prepare_for_closing();
}
}
@ -53,9 +54,14 @@ impl HeedAuthStore {
env,
keys,
action_keyid_index_expiration,
should_close_on_drop: true,
})
}
pub fn set_drop_on_close(&mut self, v: bool) {
self.should_close_on_drop = v;
}
pub fn is_empty(&self) -> Result<bool> {
let rtxn = self.env.read_txn()?;