diff options
-rw-r--r-- | common/storage.h | 1 | ||||
-rw-r--r-- | common/storage_lmdb.cpp | 40 |
2 files changed, 41 insertions, 0 deletions
diff --git a/common/storage.h b/common/storage.h index 6ae7838..075fcfd 100644 --- a/common/storage.h +++ b/common/storage.h | |||
@@ -67,6 +67,7 @@ public: | |||
67 | void scan(const char *keyData, uint keySize, | 67 | void scan(const char *keyData, uint keySize, |
68 | const std::function<bool(void *keyPtr, int keySize, void *ptr, int size)> &resultHandler, | 68 | const std::function<bool(void *keyPtr, int keySize, void *ptr, int size)> &resultHandler, |
69 | const std::function<void(const Storage::Error &error)> &errorHandler); | 69 | const std::function<void(const Storage::Error &error)> &errorHandler); |
70 | void remove(void const *keyData, uint keySize); | ||
70 | 71 | ||
71 | static std::function<void(const Storage::Error &error)> basicErrorHandler(); | 72 | static std::function<void(const Storage::Error &error)> basicErrorHandler(); |
72 | qint64 diskUsage() const; | 73 | qint64 diskUsage() const; |
diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index ce271ad..7d06f96 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp | |||
@@ -331,6 +331,46 @@ void Storage::scan(const char *keyData, uint keySize, | |||
331 | } | 331 | } |
332 | } | 332 | } |
333 | 333 | ||
334 | void Storage::remove(void const *keyData, uint keySize) | ||
335 | { | ||
336 | if (!d->env) { | ||
337 | return; | ||
338 | } | ||
339 | |||
340 | if (d->mode == ReadOnly) { | ||
341 | std::cerr << "tried to write in read-only mode." << std::endl; | ||
342 | return; | ||
343 | } | ||
344 | |||
345 | const bool implicitTransaction = !d->transaction || d->readTransaction; | ||
346 | if (implicitTransaction) { | ||
347 | // TODO: if this fails, still try the write below? | ||
348 | if (!startTransaction()) { | ||
349 | return; | ||
350 | } | ||
351 | } | ||
352 | |||
353 | int rc; | ||
354 | MDB_val key; | ||
355 | key.mv_size = keySize; | ||
356 | key.mv_data = const_cast<void*>(keyData); | ||
357 | rc = mdb_del(d->transaction, d->dbi, &key, 0); | ||
358 | |||
359 | if (rc) { | ||
360 | std::cerr << "mdb_del: " << rc << " " << mdb_strerror(rc) << std::endl; | ||
361 | } | ||
362 | |||
363 | if (implicitTransaction) { | ||
364 | if (rc) { | ||
365 | abortTransaction(); | ||
366 | } else { | ||
367 | rc = commitTransaction(); | ||
368 | } | ||
369 | } | ||
370 | |||
371 | return; | ||
372 | } | ||
373 | |||
334 | qint64 Storage::diskUsage() const | 374 | qint64 Storage::diskUsage() const |
335 | { | 375 | { |
336 | QFileInfo info(d->storageRoot + '/' + d->name + "/data.mdb"); | 376 | QFileInfo info(d->storageRoot + '/' + d->name + "/data.mdb"); |