From 23eba8203818c3903b3bc0d899ccbcd377c7999c Mon Sep 17 00:00:00 2001 From: ad hoc Date: Wed, 9 Feb 2022 13:55:36 +0100 Subject: [PATCH] fix(auth): fix env being closed when dumping --- meilisearch-auth/src/dump.rs | 5 ++++- meilisearch-auth/src/store.rs | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/meilisearch-auth/src/dump.rs b/meilisearch-auth/src/dump.rs index 4b7365005..77a4aa5ca 100644 --- a/meilisearch-auth/src/dump.rs +++ b/meilisearch-auth/src/dump.rs @@ -10,7 +10,10 @@ const KEYS_PATH: &str = "keys"; impl AuthController { pub fn dump(src: impl AsRef, dst: impl AsRef) -> Result<()> { - let store = HeedAuthStore::new(&src)?; + let mut store = HeedAuthStore::new(&src)?; + + // do not attempt to close the database on drop! + store.set_drop_on_close(false); let keys_file_path = dst.as_ref().join(KEYS_PATH); diff --git a/meilisearch-auth/src/store.rs b/meilisearch-auth/src/store.rs index 89c110f25..757a8338b 100644 --- a/meilisearch-auth/src/store.rs +++ b/meilisearch-auth/src/store.rs @@ -28,11 +28,12 @@ pub struct HeedAuthStore { env: Arc, keys: Database>, action_keyid_index_expiration: Database>>>, + 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 { let rtxn = self.env.read_txn()?;