summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-01 15:18:18 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2015-12-01 15:18:18 +0100
commit0e8a515aefafbf0595883879d269849b9154ba20 (patch)
tree76a96654ec24392ca4d15bd743abc70ca0d54b27
parent7e97222fc6b4fb546b64767e64637b7cbb7ac959 (diff)
downloadsink-0e8a515aefafbf0595883879d269849b9154ba20.tar.gz
sink-0e8a515aefafbf0595883879d269849b9154ba20.zip
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.
-rw-r--r--common/pipeline.cpp12
1 files changed, 12 insertions, 0 deletions
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<qint64> Pipeline::newEntity(void const *command, size_t size)
159 QByteArray key; 159 QByteArray key;
160 if (createEntity->entityId()) { 160 if (createEntity->entityId()) {
161 key = QByteArray(reinterpret_cast<char const*>(createEntity->entityId()->Data()), createEntity->entityId()->size()); 161 key = QByteArray(reinterpret_cast<char const*>(createEntity->entityId()->Data()), createEntity->entityId()->size());
162
163 bool found = false;
164 d->transaction.openDatabase(bufferType + ".main").scan(key, [&found](const QByteArray &, const QByteArray &value) -> bool {
165 found = true;
166 return false;
167 }, [this](const Akonadi2::Storage::Error &error) {
168 }, true);
169 if (found) {
170 ErrorMsg() << "An entity with this id already exists: " << key;
171 return KAsync::error<qint64>(0);
172 }
162 } 173 }
174
163 if (key.isEmpty()) { 175 if (key.isEmpty()) {
164 key = QUuid::createUuid().toString().toUtf8(); 176 key = QUuid::createUuid().toString().toUtf8();
165 } 177 }