summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/storage_lmdb.cpp30
1 files changed, 1 insertions, 29 deletions
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp
index 6f2142f..0458dae 100644
--- a/common/storage_lmdb.cpp
+++ b/common/storage_lmdb.cpp
@@ -477,7 +477,7 @@ int DataStore::NamedDatabase::scan(const size_t key,
477{ 477{
478 return scan(sizeTToByteArray(key), 478 return scan(sizeTToByteArray(key),
479 [&resultHandler](const QByteArray &key, const QByteArray &value) { 479 [&resultHandler](const QByteArray &key, const QByteArray &value) {
480 return resultHandler(byteArrayToSizeT(value), value); 480 return resultHandler(byteArrayToSizeT(key), value);
481 }, 481 },
482 errorHandler, /* findSubstringKeys = */ false, skipInternalKeys); 482 errorHandler, /* findSubstringKeys = */ false, skipInternalKeys);
483} 483}
@@ -901,29 +901,6 @@ void DataStore::Transaction::abort()
901 d->transaction = nullptr; 901 d->transaction = nullptr;
902} 902}
903 903
904//Ensure that we opened the correct database by comparing the expected identifier with the one
905//we write to the database on first open.
906static bool ensureCorrectDb(DataStore::NamedDatabase &database, const QByteArray &db, bool readOnly)
907{
908 bool openedTheWrongDatabase = false;
909 auto count = database.scan("__internal_dbname", [db, &openedTheWrongDatabase](const QByteArray &key, const QByteArray &value) ->bool {
910 if (value != db) {
911 SinkWarning() << "Opened the wrong database, got " << value << " instead of " << db;
912 openedTheWrongDatabase = true;
913 }
914 return false;
915 },
916 [&](const DataStore::Error &) {
917 }, false);
918 //This is the first time we open this database in a write transaction, write the db name
919 if (!count) {
920 if (!readOnly) {
921 database.write("__internal_dbname", db);
922 }
923 }
924 return !openedTheWrongDatabase;
925}
926
927DataStore::NamedDatabase DataStore::Transaction::openDatabase(const QByteArray &db, 904DataStore::NamedDatabase DataStore::Transaction::openDatabase(const QByteArray &db,
928 const std::function<void(const DataStore::Error &error)> &errorHandler, int flags) const 905 const std::function<void(const DataStore::Error &error)> &errorHandler, int flags) const
929{ 906{
@@ -947,11 +924,6 @@ DataStore::NamedDatabase DataStore::Transaction::openDatabase(const QByteArray &
947 } 924 }
948 925
949 auto database = DataStore::NamedDatabase(p); 926 auto database = DataStore::NamedDatabase(p);
950 if (!ensureCorrectDb(database, db, d->requestedRead)) {
951 SinkWarning() << "Failed to open the database correctly" << db;
952 Q_ASSERT(false);
953 return DataStore::NamedDatabase();
954 }
955 return database; 927 return database;
956} 928}
957 929