summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-11-01 22:35:32 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2021-11-01 22:35:48 +0100
commit417cc07172141763ac8b79143457116d9a423a0a (patch)
tree8163f704a74d8edf05c1e97326ffc09e3ec841ff /src
parentPrompt user when there are unverified devices (diff)
downloadnheko-417cc07172141763ac8b79143457116d9a423a0a.tar.xz
Fix crash on logout
Diffstat (limited to 'src')
-rw-r--r--src/Cache.cpp48
1 files changed, 25 insertions, 23 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp
index 45cc642d..5e28a0b8 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -969,35 +969,37 @@ Cache::nextBatchToken()
 void
 Cache::deleteData()
 {
-    this->databaseReady_ = false;
-    // TODO: We need to remove the env_ while not accepting new requests.
-    lmdb::dbi_close(env_, syncStateDb_);
-    lmdb::dbi_close(env_, roomsDb_);
-    lmdb::dbi_close(env_, invitesDb_);
-    lmdb::dbi_close(env_, readReceiptsDb_);
-    lmdb::dbi_close(env_, notificationsDb_);
+    if (this->databaseReady_) {
+        this->databaseReady_ = false;
+        // TODO: We need to remove the env_ while not accepting new requests.
+        lmdb::dbi_close(env_, syncStateDb_);
+        lmdb::dbi_close(env_, roomsDb_);
+        lmdb::dbi_close(env_, invitesDb_);
+        lmdb::dbi_close(env_, readReceiptsDb_);
+        lmdb::dbi_close(env_, notificationsDb_);
 
-    lmdb::dbi_close(env_, devicesDb_);
-    lmdb::dbi_close(env_, deviceKeysDb_);
+        lmdb::dbi_close(env_, devicesDb_);
+        lmdb::dbi_close(env_, deviceKeysDb_);
 
-    lmdb::dbi_close(env_, inboundMegolmSessionDb_);
-    lmdb::dbi_close(env_, outboundMegolmSessionDb_);
-    lmdb::dbi_close(env_, megolmSessionDataDb_);
+        lmdb::dbi_close(env_, inboundMegolmSessionDb_);
+        lmdb::dbi_close(env_, outboundMegolmSessionDb_);
+        lmdb::dbi_close(env_, megolmSessionDataDb_);
 
-    env_.close();
+        env_.close();
 
-    verification_storage.status.clear();
+        verification_storage.status.clear();
 
-    if (!cacheDirectory_.isEmpty()) {
-        QDir(cacheDirectory_).removeRecursively();
-        nhlog::db()->info("deleted cache files from disk");
-    }
+        if (!cacheDirectory_.isEmpty()) {
+            QDir(cacheDirectory_).removeRecursively();
+            nhlog::db()->info("deleted cache files from disk");
+        }
 
-    deleteSecret(mtx::secret_storage::secrets::megolm_backup_v1);
-    deleteSecret(mtx::secret_storage::secrets::cross_signing_master);
-    deleteSecret(mtx::secret_storage::secrets::cross_signing_user_signing);
-    deleteSecret(mtx::secret_storage::secrets::cross_signing_self_signing);
-    deleteSecret("pickle_secret", true);
+        deleteSecret(mtx::secret_storage::secrets::megolm_backup_v1);
+        deleteSecret(mtx::secret_storage::secrets::cross_signing_master);
+        deleteSecret(mtx::secret_storage::secrets::cross_signing_user_signing);
+        deleteSecret(mtx::secret_storage::secrets::cross_signing_self_signing);
+        deleteSecret("pickle_secret", true);
+    }
 }
 
 //! migrates db to the current format