diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-03-26 15:05:41 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-03-26 15:05:41 +0200 |
commit | 80afd7070f2d8e57cab2fe55fef611623fdb75f0 (patch) | |
tree | 5ec29f1bfece2b4344d040db232f7c4c0f746b73 /common/storage_lmdb.cpp | |
parent | b334872e612433aee1284561fa247127bcdeeaf8 (diff) | |
download | sink-80afd7070f2d8e57cab2fe55fef611623fdb75f0.tar.gz sink-80afd7070f2d8e57cab2fe55fef611623fdb75f0.zip |
Make sure we initialize the environment correctly and only set the db version when creating it
Diffstat (limited to 'common/storage_lmdb.cpp')
-rw-r--r-- | common/storage_lmdb.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index 9d0bd6b..49f30b5 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp | |||
@@ -566,6 +566,11 @@ public: | |||
566 | const int rc = mdb_txn_begin(env, NULL, requestedRead ? MDB_RDONLY : 0, &transaction); | 566 | const int rc = mdb_txn_begin(env, NULL, requestedRead ? MDB_RDONLY : 0, &transaction); |
567 | // Trace_area("storage." + name.toLatin1()) << "Started transaction " << mdb_txn_id(transaction) << transaction; | 567 | // Trace_area("storage." + name.toLatin1()) << "Started transaction " << mdb_txn_id(transaction) << transaction; |
568 | if (rc) { | 568 | if (rc) { |
569 | unsigned int flags; | ||
570 | mdb_env_get_flags(env, &flags); | ||
571 | if (flags & MDB_RDONLY && !requestedRead) { | ||
572 | SinkError() << "Tried to open a write transation in a read-only enironment"; | ||
573 | } | ||
569 | defaultErrorHandler(Error(name.toLatin1(), ErrorCodes::GenericError, "Error while opening transaction: " + QByteArray(mdb_strerror(rc)))); | 574 | defaultErrorHandler(Error(name.toLatin1(), ErrorCodes::GenericError, "Error while opening transaction: " + QByteArray(mdb_strerror(rc)))); |
570 | } | 575 | } |
571 | } | 576 | } |
@@ -916,10 +921,14 @@ DataStore::~DataStore() | |||
916 | delete d; | 921 | delete d; |
917 | } | 922 | } |
918 | 923 | ||
924 | bool DataStore::exists(const QString &storageRoot, const QString &name) | ||
925 | { | ||
926 | return QFileInfo(storageRoot + '/' + name + "/data.mdb").exists(); | ||
927 | } | ||
928 | |||
919 | bool DataStore::exists() const | 929 | bool DataStore::exists() const |
920 | { | 930 | { |
921 | QFileInfo info(d->storageRoot + '/' + d->name + "/data.mdb"); | 931 | return (d->env != 0) && DataStore::exists(d->storageRoot, d->name); |
922 | return (d->env != 0) && info.exists(); | ||
923 | } | 932 | } |
924 | 933 | ||
925 | DataStore::Transaction DataStore::createTransaction(AccessMode type, const std::function<void(const DataStore::Error &error)> &errorHandlerArg) | 934 | DataStore::Transaction DataStore::createTransaction(AccessMode type, const std::function<void(const DataStore::Error &error)> &errorHandlerArg) |