From e56166cf75aff15eda05be5c33825bd926b9ccb2 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Fri, 16 Jan 2015 13:26:42 +0100 Subject: Fixed storage removal. We have to remove any open environments as well. --- common/storage_lmdb.cpp | 8 +++++--- tests/storagetest.cpp | 21 +++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index 2dc4817..591d761 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp @@ -396,12 +396,14 @@ qint64 Storage::diskUsage() const void Storage::removeFromDisk() const { - QDir dir(d->storageRoot + '/' + d->name); - // dir.remove("data.mdb"); - // dir.remove("lock.mdb"); + const QString fullPath(d->storageRoot + '/' + d->name); + QMutexLocker locker(&d->sMutex); + QDir dir(fullPath); if (!dir.removeRecursively()) { qWarning() << "Failed to remove directory" << d->storageRoot << d->name; } + auto env = d->sEnvironments.take(fullPath); + delete env; } } // namespace Akonadi2 diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index 516fe85..5b4a0ba 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp @@ -63,12 +63,21 @@ private Q_SLOTS: storage.removeFromDisk(); } - void cleanupTestCase() + void cleanup() { Akonadi2::Storage storage(testDataPath, dbName); storage.removeFromDisk(); } + void testCleanup() + { + populate(1); + Akonadi2::Storage storage(testDataPath, dbName); + storage.removeFromDisk(); + QFileInfo info(testDataPath + "/" + dbName); + QVERIFY(!info.exists()); + } + void testRead() { const int count = 100; @@ -82,9 +91,6 @@ private Q_SLOTS: QVERIFY(verify(storage, i)); } } - - Akonadi2::Storage storage(testDataPath, dbName); - storage.removeFromDisk(); } void testScan() @@ -120,9 +126,6 @@ private Q_SLOTS: QVERIFY(!foundInvalidValue); QCOMPARE(hit, 1); } - - Akonadi2::Storage storage(testDataPath, dbName); - storage.removeFromDisk(); } void testTurnReadToWrite() @@ -135,14 +138,13 @@ private Q_SLOTS: }); return false; }); - store.removeFromDisk(); } void testReadEmptyDb() { bool gotResult = false; bool gotError = false; - Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite); + Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadOnly); store.scan(0, 0, [&](void *keyValue, int keySize, void *dataValue, int dataSize) -> bool { gotResult = true; return false; @@ -152,7 +154,6 @@ private Q_SLOTS: }); QVERIFY(!gotResult); QVERIFY(!gotError); - store.removeFromDisk(); } void testConcurrentRead() -- cgit v1.2.3