summaryrefslogtreecommitdiff
path: root/plugins/Dbx_mdbx/src/dbcrypt.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2019-02-22 19:01:30 +0300
committerGeorge Hazan <ghazan@miranda.im>2019-02-22 19:01:30 +0300
commita79f25d3146f1c706c2908310bb348f8e9c127de (patch)
treeab1e50f966b38b2135008a403c454e679a48a073 /plugins/Dbx_mdbx/src/dbcrypt.cpp
parentff6ae8a76d49aa90ff559c7c8be51a30bc24a9cf (diff)
Dbx_Mdbx: fix for hangup during database encryption
Diffstat (limited to 'plugins/Dbx_mdbx/src/dbcrypt.cpp')
-rw-r--r--plugins/Dbx_mdbx/src/dbcrypt.cpp96
1 files changed, 48 insertions, 48 deletions
diff --git a/plugins/Dbx_mdbx/src/dbcrypt.cpp b/plugins/Dbx_mdbx/src/dbcrypt.cpp
index 898ba18de7..47bf3c3e34 100644
--- a/plugins/Dbx_mdbx/src/dbcrypt.cpp
+++ b/plugins/Dbx_mdbx/src/dbcrypt.cpp
@@ -163,13 +163,13 @@ int CDbxMDBX::EnableEncryption(bool bEncrypted)
if (m_bEncrypted == bEncrypted)
return 0;
+ std::vector<MEVENT> lstEvents;
{
txn_ptr_ro txnro(m_txn_ro);
MDBX_stat st;
mdbx_dbi_stat(txnro, m_dbEvents, &st, sizeof(st));
- std::vector<MEVENT> lstEvents;
lstEvents.reserve(st.ms_entries);
{
cursor_ptr_ro cursor(m_curEvents);
@@ -179,59 +179,59 @@ int CDbxMDBX::EnableEncryption(bool bEncrypted)
lstEvents.push_back(hDbEvent);
}
}
+ }
- do {
- size_t portion = min(lstEvents.size(), 1000);
-
- txn_ptr trnlck(StartTran());
- for (size_t i = 0; i < portion; i++) {
- MEVENT &hDbEvent = lstEvents[i];
- MDBX_val key = { &hDbEvent, sizeof(MEVENT) }, data;
- int rc = mdbx_get(trnlck, m_dbEvents, &key, &data);
- if (rc != MDBX_SUCCESS) {
- if (rc != MDBX_NOTFOUND)
- assert(rc == MDBX_SUCCESS);
- continue;
- }
+ do {
+ size_t portion = min(lstEvents.size(), 1000);
- const DBEvent *dbEvent = (const DBEvent*)data.iov_base;
- const BYTE *pBlob = (BYTE*)(dbEvent + 1);
-
- if (((dbEvent->flags & DBEF_ENCRYPTED) != 0) != bEncrypted) {
- mir_ptr<BYTE> pNewBlob;
- size_t nNewBlob;
- uint32_t dwNewFlags;
-
- if (dbEvent->flags & DBEF_ENCRYPTED) {
- pNewBlob = (BYTE*)m_crypto->decodeBuffer(pBlob, dbEvent->cbBlob, &nNewBlob);
- dwNewFlags = dbEvent->flags & (~DBEF_ENCRYPTED);
- }
- else {
- pNewBlob = m_crypto->encodeBuffer(pBlob, dbEvent->cbBlob, &nNewBlob);
- dwNewFlags = dbEvent->flags | DBEF_ENCRYPTED;
- }
-
- data.iov_len = sizeof(DBEvent) + nNewBlob;
- mir_ptr<BYTE> pData((BYTE*)mir_alloc(data.iov_len));
- data.iov_base = pData.get();
-
- DBEvent *pNewDBEvent = (DBEvent *)data.iov_base;
- *pNewDBEvent = *dbEvent;
- pNewDBEvent->cbBlob = (uint16_t)nNewBlob;
- pNewDBEvent->flags = dwNewFlags;
- memcpy(pNewDBEvent + 1, pNewBlob, nNewBlob);
-
- if (mdbx_put(trnlck, m_dbEvents, &key, &data, 0) != MDBX_SUCCESS)
- return 1;
- }
+ txn_ptr trnlck(StartTran());
+ for (size_t i = 0; i < portion; i++) {
+ MEVENT &hDbEvent = lstEvents[i];
+ MDBX_val key = { &hDbEvent, sizeof(MEVENT) }, data;
+ int rc = mdbx_get(trnlck, m_dbEvents, &key, &data);
+ if (rc != MDBX_SUCCESS) {
+ if (rc != MDBX_NOTFOUND)
+ assert(rc == MDBX_SUCCESS);
+ continue;
}
- lstEvents.erase(lstEvents.begin(), lstEvents.begin()+portion);
- if (trnlck.commit() != MDBX_SUCCESS)
- return 1;
+ const DBEvent *dbEvent = (const DBEvent*)data.iov_base;
+ const BYTE *pBlob = (BYTE*)(dbEvent + 1);
+
+ if (((dbEvent->flags & DBEF_ENCRYPTED) != 0) != bEncrypted) {
+ mir_ptr<BYTE> pNewBlob;
+ size_t nNewBlob;
+ uint32_t dwNewFlags;
+
+ if (dbEvent->flags & DBEF_ENCRYPTED) {
+ pNewBlob = (BYTE*)m_crypto->decodeBuffer(pBlob, dbEvent->cbBlob, &nNewBlob);
+ dwNewFlags = dbEvent->flags & (~DBEF_ENCRYPTED);
+ }
+ else {
+ pNewBlob = m_crypto->encodeBuffer(pBlob, dbEvent->cbBlob, &nNewBlob);
+ dwNewFlags = dbEvent->flags | DBEF_ENCRYPTED;
+ }
+
+ data.iov_len = sizeof(DBEvent) + nNewBlob;
+ mir_ptr<BYTE> pData((BYTE*)mir_alloc(data.iov_len));
+ data.iov_base = pData.get();
+
+ DBEvent *pNewDBEvent = (DBEvent *)data.iov_base;
+ *pNewDBEvent = *dbEvent;
+ pNewDBEvent->cbBlob = (uint16_t)nNewBlob;
+ pNewDBEvent->flags = dwNewFlags;
+ memcpy(pNewDBEvent + 1, pNewBlob, nNewBlob);
+
+ if (mdbx_put(trnlck, m_dbEvents, &key, &data, 0) != MDBX_SUCCESS)
+ return 1;
+ }
}
- while (lstEvents.size() > 0);
+
+ lstEvents.erase(lstEvents.begin(), lstEvents.begin()+portion);
+ if (trnlck.commit() != MDBX_SUCCESS)
+ return 1;
}
+ while (lstEvents.size() > 0);
txn_ptr trnlck(StartTran());
MDBX_val key = { DBKey_Crypto_IsEncrypted, sizeof(DBKey_Crypto_IsEncrypted) }, value = { &bEncrypted, sizeof(bool) };