From 49b1c5c3b342a84ec71e9b7dfd06a80b6d6e6c96 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 10 Dec 2015 10:29:12 +0100 Subject: Remove all databases from disk --- common/clientapi.cpp | 13 ++++++++++++- common/clientapi.h | 5 +++++ examples/client/main.cpp | 5 +++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/common/clientapi.cpp b/common/clientapi.cpp index 255ea21..061d920 100644 --- a/common/clientapi.cpp +++ b/common/clientapi.cpp @@ -24,17 +24,18 @@ #include #include #include +#include #include #include #include "resourceaccess.h" #include "commands.h" #include "resourcefacade.h" -#include "log.h" #include "definitions.h" #include "resourceconfig.h" #include "facadefactory.h" #include "modelresult.h" +#include "storage.h" #include "log.h" namespace Akonadi2 @@ -178,6 +179,16 @@ KAsync::Job Store::start(const QByteArray &identifier) }); } +void Store::removeFromDisk(const QByteArray &identifier) +{ + //TODO By calling the resource executable with a --remove option instead + //we can ensure that no other resource process is running at the same time + QDir dir(Akonadi2::storageLocation()); + for (const auto &folder : dir.entryList(QStringList() << identifier + "*")) { + Akonadi2::Storage(Akonadi2::storageLocation(), folder, Akonadi2::Storage::ReadWrite).removeFromDisk(); + } +} + KAsync::Job Store::synchronize(const Akonadi2::Query &query) { Trace() << "synchronize"; diff --git a/common/clientapi.h b/common/clientapi.h index 074aabc..3d9095d 100644 --- a/common/clientapi.h +++ b/common/clientapi.h @@ -93,6 +93,11 @@ public: * Synchronize data to local cache. */ static KAsync::Job synchronize(const Akonadi2::Query &query); + + /** + * Removes a resource from disk. + */ + static void removeFromDisk(const QByteArray &resourceIdentifier); }; diff --git a/examples/client/main.cpp b/examples/client/main.cpp index e0d9078..59ff9d9 100644 --- a/examples/client/main.cpp +++ b/examples/client/main.cpp @@ -29,6 +29,8 @@ #include "common/domain/folder.h" #include "common/resourceconfig.h" #include "common/log.h" +#include "common/storage.h" +#include "common/definitions.h" #include "console.h" #include @@ -153,8 +155,7 @@ int main(int argc, char *argv[]) if (cliOptions.isSet("clear")) { qDebug() << "Clearing"; for (const auto &resource : resources) { - Akonadi2::Storage store(Akonadi2::Store::storageLocation(), resource, Akonadi2::Storage::ReadWrite); - store.removeFromDisk(); + Akonadi2::Store::removeFromDisk(resource.toLatin1()); } return 0; } -- cgit v1.2.3