From dabd408dcd372f16c7934597db30346869cd8ad8 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 29 May 2016 15:19:21 +0200 Subject: Fixed genericresource so it works with the maildirresourcetest --- common/sourcewriteback.cpp | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'common/sourcewriteback.cpp') diff --git a/common/sourcewriteback.cpp b/common/sourcewriteback.cpp index 1ef20d2..1c07577 100644 --- a/common/sourcewriteback.cpp +++ b/common/sourcewriteback.cpp @@ -54,8 +54,7 @@ RemoteIdMap &SourceWriteBack::syncStore() KAsync::Job SourceWriteBack::replay(const QByteArray &type, const QByteArray &key, const QByteArray &value) { - mTransaction = mStorage.createTransaction(Sink::Storage::ReadOnly); - mSyncTransaction = mSyncStorage.createTransaction(Sink::Storage::ReadWrite); + Trace() << "Replaying" << type << key; Sink::EntityBuffer buffer(value); const Sink::Entity &entity = buffer.entity(); @@ -65,7 +64,14 @@ KAsync::Job SourceWriteBack::replay(const QByteArray &type, const QByteArr Trace() << "Change is coming from the source"; return KAsync::null(); } - const qint64 revision = metadataBuffer ? metadataBuffer->revision() : -1; + Q_ASSERT(!mSyncStore); + Q_ASSERT(!mEntityStore); + Q_ASSERT(!mTransaction); + Q_ASSERT(!mSyncTransaction); + mTransaction = mStorage.createTransaction(Sink::Storage::ReadOnly); + mSyncTransaction = mSyncStorage.createTransaction(Sink::Storage::ReadWrite); + + // const qint64 revision = metadataBuffer ? metadataBuffer->revision() : -1; const auto operation = metadataBuffer ? metadataBuffer->operation() : Sink::Operation_Creation; const auto uid = Sink::Storage::uidFromKey(key); QByteArray oldRemoteId; @@ -84,32 +90,38 @@ KAsync::Job SourceWriteBack::replay(const QByteArray &type, const QByteArr job = replay(mail, operation, oldRemoteId); } - return job.then([this, operation, type, uid](const QByteArray &remoteId) { - Trace() << "Replayed change with remote id: " << remoteId; + return job.then([this, operation, type, uid, oldRemoteId](const QByteArray &remoteId) { if (operation == Sink::Operation_Creation) { + Trace() << "Replayed creation with remote id: " << remoteId; if (remoteId.isEmpty()) { Warning() << "Returned an empty remoteId from the creation"; } else { syncStore().recordRemoteId(type, uid, remoteId); } } else if (operation == Sink::Operation_Modification) { + Trace() << "Replayed modification with remote id: " << remoteId; if (remoteId.isEmpty()) { Warning() << "Returned an empty remoteId from the creation"; } else { syncStore().updateRemoteId(type, uid, remoteId); } } else if (operation == Sink::Operation_Removal) { - syncStore().removeRemoteId(type, uid, remoteId); + Trace() << "Replayed removal with remote id: " << oldRemoteId; + syncStore().removeRemoteId(type, uid, oldRemoteId); } else { - Warning() << "Unkown operation" << operation; + ErrorMsg() << "Unkown operation" << operation; } + mSyncStore.clear(); + mEntityStore.clear(); mTransaction.abort(); mSyncTransaction.commit(); + }, [this](int errorCode, const QString &errorMessage) { + Warning() << "Failed to replay change: " << errorMessage; mSyncStore.clear(); mEntityStore.clear(); - }, [](int errorCode, const QString &errorMessage) { - Warning() << "Failed to replay change: " << errorMessage; + mTransaction.abort(); + mSyncTransaction.commit(); }); } -- cgit v1.2.3