diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-01 15:18:18 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-01 15:18:18 +0100 |
commit | 0e8a515aefafbf0595883879d269849b9154ba20 (patch) | |
tree | 76a96654ec24392ca4d15bd743abc70ca0d54b27 /common/pipeline.cpp | |
parent | 7e97222fc6b4fb546b64767e64637b7cbb7ac959 (diff) | |
download | sink-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.
Diffstat (limited to 'common/pipeline.cpp')
-rw-r--r-- | common/pipeline.cpp | 12 |
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 | } |