Commit 7c044c4b authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

Merge branch 'Applications/16.04'

parents 4b6391ad 3d35aaf1
......@@ -644,8 +644,20 @@ public:
//Prevent double result emission
Q_ASSERT(!resultEmitted);
if (!resultEmitted) {
resultEmitted = true;
q->emitResult();
if (q->hasSubjobs()) {
// If there are subjobs, pick one, wait for it to finish, then
// try again. This way we make sure we don't emit result() signal
// while there is still a Transaction job running
KJob *subjob = q->subjobs().at(0);
connect(subjob, &KJob::result,
q, [this](KJob*) {
emitResult();
},
Qt::QueuedConnection);
} else {
resultEmitted = true;
q->emitResult();
}
}
}
......
......@@ -74,7 +74,7 @@ void CollectionCopyJob::doStart()
bool CollectionCopyJob::doHandleResponse(qint64 tag, const Protocol::Command &response)
{
if (!response.isResponse() || response.type() != Protocol::Command::CreateCollection) {
if (!response.isResponse() || response.type() != Protocol::Command::CopyCollection) {
return Job::doHandleResponse(tag, response);
}
......
......@@ -62,7 +62,14 @@ void JobPrivate::handleResponse(qint64 tag, const Protocol::Command &response)
}
}
if (mReadingFinished) {
Q_ASSERT(!mReadingFinished);
qCWarning(AKONADICORE_LOG) << "Received response for a job that does not expect any more data, ignoring";
return;
}
if (q->doHandleResponse(tag, response)) {
mReadingFinished = true;
QTimer::singleShot(0, q, SLOT(delayedEmitResult()));
}
}
......@@ -149,8 +156,13 @@ void JobPrivate::aboutToFinish()
void JobPrivate::delayedEmitResult()
{
Q_Q(Job);
aboutToFinish();
q->emitResult();
if (q->hasSubjobs()) {
// We still have subjobs, wait for them to finish
mFinishPending = true;
} else {
aboutToFinish();
q->emitResult();
}
}
void JobPrivate::startQueued()
......@@ -190,6 +202,9 @@ void JobPrivate::startNext()
Job *job = qobject_cast<Akonadi::Job *>(q->subjobs().at(0));
Q_ASSERT(job);
job->d_ptr->startQueued();
} else if (mFinishPending && !q->hasSubjobs()) {
// The last subjob we've been waiting for has finished, emitResult() finally
QTimer::singleShot(0, q, SLOT(delayedEmitResult()));
}
}
......@@ -343,17 +358,10 @@ bool Job::removeSubjob(KJob *job)
bool Job::doHandleResponse(qint64 tag, const Protocol::Command &command)
{
// FIXME: We cannot set an error here due to how CollectionSync works: CS
// can sometimes schedule TransactionSequences and emitResult in a way that
// the Session dispatches next job in queue without TransactionSequence's
// TransactionCommitJob finishing: the we get the response for TCJ out-of-order
// and it's received by the currently running job instead of the TCJ.
qCDebug(AKONADICORE_LOG) << this << "Unhandled response: " << tag << command.debugString();
/*
setError(Unknown);
setErrorText(i18n("Unexpected response"));
emitResult();
*/
return true;
}
......
......@@ -44,7 +44,9 @@ public:
, mTag(-1)
, mSession(0)
, mWriteFinished(false)
, mReadingFinished(false)
, mStarted(false)
, mFinishPending(false)
{
}
......@@ -128,7 +130,9 @@ public:
qint64 mTag;
Session *mSession;
bool mWriteFinished;
bool mReadingFinished;
bool mStarted;
bool mFinishPending;
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment