summaryrefslogtreecommitdiffstats
path: root/common/storage_lmdb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/storage_lmdb.cpp')
-rw-r--r--common/storage_lmdb.cpp40
1 files changed, 40 insertions, 0 deletions
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
334void 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
334qint64 Storage::diskUsage() const 374qint64 Storage::diskUsage() const
335{ 375{
336 QFileInfo info(d->storageRoot + '/' + d->name + "/data.mdb"); 376 QFileInfo info(d->storageRoot + '/' + d->name + "/data.mdb");