From 738c1275e652ed16e0f3ebb04b305e6c78f67cf3 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 8 Dec 2015 16:13:12 +0100 Subject: Catch the case when we try to remove an entity that has already been removed --- common/pipeline.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'common/pipeline.cpp') diff --git a/common/pipeline.cpp b/common/pipeline.cpp index 01db980..d850154 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp @@ -339,6 +339,34 @@ KAsync::Job Pipeline::deletedEntity(void const *command, size_t size) const QByteArray bufferType = QByteArray(reinterpret_cast(deleteEntity->domainType()->Data()), deleteEntity->domainType()->size()); const QByteArray key = QByteArray(reinterpret_cast(deleteEntity->entityId()->Data()), deleteEntity->entityId()->size()); + bool found = false; + bool alreadyRemoved = false; + d->transaction.openDatabase(bufferType + ".main").findLatest(key, [&found, &alreadyRemoved](const QByteArray &key, const QByteArray &data) -> bool { + Akonadi2::EntityBuffer buffer(const_cast(data.data()), data.size()); + auto entity = Akonadi2::GetEntity(data.data()); + if (entity && entity->metadata()) { + auto metadata = Akonadi2::GetMetadata(entity->metadata()->Data()); + found = true; + if (metadata->operation() == Akonadi2::Operation_Removal) { + alreadyRemoved = true; + } + + } + return false; + }, + [](const Storage::Error &error) { + Warning() << "Failed to read old revision from storage: " << error.message; + }); + + if (!found) { + Warning() << "Failed to find entity " << key; + return KAsync::error(0); + } + if (alreadyRemoved) { + Warning() << "Entity is already removed " << key; + return KAsync::error(0); + } + const qint64 newRevision = Akonadi2::Storage::maxRevision(d->transaction) + 1; //Add metadata buffer -- cgit v1.2.3