From acd2902aaecaba864c5673adead98e59222e0fc9 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 22 May 2016 14:15:26 +0200 Subject: Propagate the synchronization error. --- common/genericresource.cpp | 8 ++++++-- common/listener.cpp | 3 +++ common/resourceaccess.cpp | 13 +++++++++---- 3 files changed, 18 insertions(+), 6 deletions(-) (limited to 'common') diff --git a/common/genericresource.cpp b/common/genericresource.cpp index 8704e5a..b32a22b 100644 --- a/common/genericresource.cpp +++ b/common/genericresource.cpp @@ -459,16 +459,20 @@ void GenericResource::processCommand(int commandId, const QByteArray &data) KAsync::Job GenericResource::synchronizeWithSource() { - return KAsync::start([this]() { + return KAsync::start([this](KAsync::Future &future) { Log() << " Synchronizing"; // Changereplay would deadlock otherwise when trying to open the synchronization store enableChangeReplay(false); auto mainStore = QSharedPointer::create(Sink::storageLocation(), mResourceInstanceIdentifier, Sink::Storage::ReadOnly); auto syncStore = QSharedPointer::create(Sink::storageLocation(), mResourceInstanceIdentifier + ".synchronization", Sink::Storage::ReadWrite); synchronizeWithSource(*mainStore, *syncStore) - .then([this, mainStore, syncStore]() { + .then([this, mainStore, syncStore, &future]() { Log() << "Done Synchronizing"; enableChangeReplay(true); + future.setFinished(); + }, [this, &future](int errorCode, const QString &error) { + enableChangeReplay(true); + future.setError(errorCode, error); }) .exec(); }); diff --git a/common/listener.cpp b/common/listener.cpp index de20b2c..6cbf40f 100644 --- a/common/listener.cpp +++ b/common/listener.cpp @@ -252,6 +252,9 @@ void Listener::processCommand(int commandId, uint messageId, const QByteArray &c job.then([callback, timer]() { Trace() << "Sync took " << Sink::Log::TraceTime(timer->elapsed()); callback(true); + }, [callback](int errorCode, const QString &msg) { + Warning() << "Sync failed: " << msg; + callback(false); }) .exec(); return; diff --git a/common/resourceaccess.cpp b/common/resourceaccess.cpp index 991c930..b294221 100644 --- a/common/resourceaccess.cpp +++ b/common/resourceaccess.cpp @@ -96,7 +96,7 @@ public: QVector> commandQueue; QMap> pendingCommands; QMultiMap> resultHandler; - QSet completeCommands; + QHash completeCommands; uint messageId; bool openingSocket; }; @@ -121,12 +121,17 @@ void ResourceAccess::Private::abortPendingOperations() void ResourceAccess::Private::callCallbacks() { - for (auto id : completeCommands) { + for (auto id : completeCommands.keys()) { + const bool success = completeCommands.value(id); // We remove the callbacks first because the handler can kill resourceaccess directly const auto callbacks = resultHandler.values(id); resultHandler.remove(id); for (auto handler : callbacks) { - handler(0, QString()); + if (success) { + handler(0, QString()); + } else { + handler(1, "Command failed."); + } } } } @@ -536,7 +541,7 @@ bool ResourceAccess::processMessageBuffer() auto buffer = Commands::GetCommandCompletion(d->partialMessageBuffer.constData() + headerSize); Log() << QString("Command with messageId %1 completed %2").arg(buffer->id()).arg(buffer->success() ? "sucessfully" : "unsuccessfully"); - d->completeCommands << buffer->id(); + d->completeCommands.insert(buffer->id(), buffer->success()); // The callbacks can result in this object getting destroyed directly, so we need to ensure we finish our work first queuedInvoke([=]() { d->callCallbacks(); }, this); break; -- cgit v1.2.3