summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdbx/src
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2020-08-08 21:11:15 +0300
committerGeorge Hazan <ghazan@miranda.im>2020-08-08 21:11:15 +0300
commit510f97e01b6c5ef92005eda0c530272aaf150b9f (patch)
tree316262791801408c53133303e1d7c36e121161bc /plugins/Dbx_mdbx/src
parent62e4253a9a92179d184ffb8dcb8947d4d38b9aea (diff)
filtering out orphaned settings
Diffstat (limited to 'plugins/Dbx_mdbx/src')
-rw-r--r--plugins/Dbx_mdbx/src/dbcheck.cpp28
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.cpp3
-rw-r--r--plugins/Dbx_mdbx/src/dbintf.h1
3 files changed, 30 insertions, 2 deletions
diff --git a/plugins/Dbx_mdbx/src/dbcheck.cpp b/plugins/Dbx_mdbx/src/dbcheck.cpp
index f32469c6c4..527e0dd9bb 100644
--- a/plugins/Dbx_mdbx/src/dbcheck.cpp
+++ b/plugins/Dbx_mdbx/src/dbcheck.cpp
@@ -57,7 +57,7 @@ int CDbxMDBX::CheckEvents1(void)
}
/////////////////////////////////////////////////////////////////////////////////////////
-// we are tracing EventId tables to verify that they have correct event ids
+// we are tracing EventId table to verify that they have correct event ids
int CDbxMDBX::CheckEvents2(void)
{
@@ -77,3 +77,29 @@ int CDbxMDBX::CheckEvents2(void)
trnlck.commit();
return 0;
}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// we are tracing Settings table to verify that they have correct contact ids
+
+int CDbxMDBX::CheckEvents3(void)
+{
+ txn_ptr trnlck(StartTran());
+ cursor_ptr cursor(trnlck, m_dbSettings);
+
+ MDBX_val key, data;
+ for (int ret = mdbx_cursor_get(cursor, &key, &data, MDBX_FIRST); ret == MDBX_SUCCESS; ret = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT)) {
+ auto *pKey = (DBSettingKey *)key.iov_base;
+
+ if (pKey->hContact) {
+ auto *cc = m_cache->GetCachedContact(pKey->hContact);
+ if (cc == nullptr) {
+ mdbx_cursor_del(cursor, 0);
+ cb->pfnAddLogMessage(STATUS_ERROR, CMStringW(FORMAT, TranslateT("Orphaned setting with wrong contact ID %08X, deleting"), pKey->hContact));
+ continue;
+ }
+ }
+ }
+
+ trnlck.commit();
+ return 0;
+}
diff --git a/plugins/Dbx_mdbx/src/dbintf.cpp b/plugins/Dbx_mdbx/src/dbintf.cpp
index 18b570a3e6..0dc12bc648 100644
--- a/plugins/Dbx_mdbx/src/dbintf.cpp
+++ b/plugins/Dbx_mdbx/src/dbintf.cpp
@@ -306,7 +306,8 @@ int CDbxMDBX::Start(DBCHeckCallback *callback)
static CheckWorker Workers[] =
{
&CDbxMDBX::CheckEvents1,
- &CDbxMDBX::CheckEvents2
+ &CDbxMDBX::CheckEvents2,
+ &CDbxMDBX::CheckEvents3,
};
int CDbxMDBX::CheckDb(int phase)
diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h
index 50b10109f8..3c7efb03d7 100644
--- a/plugins/Dbx_mdbx/src/dbintf.h
+++ b/plugins/Dbx_mdbx/src/dbintf.h
@@ -253,6 +253,7 @@ public:
int CheckEvents1(void);
int CheckEvents2(void);
+ int CheckEvents3(void);
__forceinline LPSTR GetMenuTitle() const { return m_bUsesPassword ? (char*)LPGEN("Change/remove password") : (char*)LPGEN("Set password"); }