From 0e8a515aefafbf0595883879d269849b9154ba20 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 1 Dec 2015 15:18:18 +0100 Subject: Pipeline: Ensure a created entity has a new id. Since we can now inject entity ids we have to ensure they are not already existing. --- common/pipeline.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'common') diff --git a/common/pipeline.cpp b/common/pipeline.cpp index acccd90..01db980 100644 --- a/common/pipeline.cpp +++ b/common/pipeline.cpp @@ -159,7 +159,19 @@ KAsync::Job Pipeline::newEntity(void const *command, size_t size) QByteArray key; if (createEntity->entityId()) { key = QByteArray(reinterpret_cast(createEntity->entityId()->Data()), createEntity->entityId()->size()); + + bool found = false; + d->transaction.openDatabase(bufferType + ".main").scan(key, [&found](const QByteArray &, const QByteArray &value) -> bool { + found = true; + return false; + }, [this](const Akonadi2::Storage::Error &error) { + }, true); + if (found) { + ErrorMsg() << "An entity with this id already exists: " << key; + return KAsync::error(0); + } } + if (key.isEmpty()) { key = QUuid::createUuid().toString().toUtf8(); } -- cgit v1.2.3