diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-01-11 16:09:11 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-01-11 16:09:11 +0100 |
commit | a4aeea4322252725165cb62390e880f2861035a6 (patch) | |
tree | e7604e7b94b4a0dbbce31e4ca1507827a6d87a01 /common/storage_lmdb.cpp | |
parent | c95980b7845b4295070be3271519dc3b844422c8 (diff) | |
download | sink-a4aeea4322252725165cb62390e880f2861035a6.tar.gz sink-a4aeea4322252725165cb62390e880f2861035a6.zip |
Remove from storage call.
Diffstat (limited to 'common/storage_lmdb.cpp')
-rw-r--r-- | common/storage_lmdb.cpp | 40 |
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 | ||
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"); |