Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:15.0:Update
kdepim-runtime
0002-IMAP-resource-fix-data-loss-on-connection-...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0002-IMAP-resource-fix-data-loss-on-connection-lost-depen.patch of Package kdepim-runtime
From c668d92ee54124291ce249be16167b89e0ecac2e Mon Sep 17 00:00:00 2001 From: David Faure <faure@kde.org> Date: Sun, 22 Apr 2018 00:37:04 +0200 Subject: [PATCH 2/2] IMAP resource: fix data loss on connection lost, depending on the current task If the current task is e.g. uploading an item to the server, we don't want to cancelTask (which means give up and never try again), we want to deferTask, so we try again later. Otherwise, well, this is how we end up with items without a remote id, which makes syncing that folder much slower every time due to the item count mismatch. Abstracted with a new method abortTask, which calls cancel or defer depending on the type of task. Differential Revision: https://phabricator.kde.org/D12427 --- resources/imap/resourcetask.cpp | 77 ++++++++++++++--------------------------- resources/imap/resourcetask.h | 1 + 2 files changed, 27 insertions(+), 51 deletions(-) diff --git a/resources/imap/resourcetask.cpp b/resources/imap/resourcetask.cpp index 87f1ed70a..e9be912e8 100644 --- a/resources/imap/resourcetask.cpp +++ b/resources/imap/resourcetask.cpp @@ -68,25 +68,33 @@ void ResourceTask::start(SessionPool *pool) if (m_sessionRequestId <= 0) { m_sessionRequestId = 0; + abortTask(QString()); + // In this case we were likely disconnected, try to get the resource online + m_resource->scheduleConnectionAttempt(); + } +} + +void ResourceTask::abortTask(const QString &errorString) +{ + if (!mCancelled) { + mCancelled = true; + switch (m_actionIfNoSession) { - case CancelIfNoSession: - qCDebug(IMAPRESOURCE_LOG) << "Cancelling this request. Probably there is no connection."; - m_resource->cancelTask(i18n("There is currently no connection to the IMAP server.")); - break; - - case DeferIfNoSession: - qCDebug(IMAPRESOURCE_LOG) << "Defering this request. Probably there is no connection."; - m_resource->deferTask(); - break; + case CancelIfNoSession: + qCDebug(IMAPRESOURCE_LOG) << "Cancelling this request."; + m_resource->cancelTask(errorString.isEmpty() ? i18n("Unable to connect to the IMAP server.") : errorString); + break; + + case DeferIfNoSession: + qCDebug(IMAPRESOURCE_LOG) << "Defering this request."; + m_resource->deferTask(); + break; } - - // In this case we were likely disconnect, try to get the resource online - m_resource->scheduleConnectionAttempt(); - deleteLater(); } + deleteLater(); } -void ResourceTask::onSessionRequested(qint64 requestId, KIMAP::Session *session, int errorCode, const QString & /*errorString*/) +void ResourceTask::onSessionRequested(qint64 requestId, KIMAP::Session *session, int errorCode, const QString &errorString) { if (requestId != m_sessionRequestId) { // Not for us, ignore @@ -98,39 +106,7 @@ void ResourceTask::onSessionRequested(qint64 requestId, KIMAP::Session *session, m_sessionRequestId = 0; if (errorCode != SessionPool::NoError) { - switch (m_actionIfNoSession) { - case CancelIfNoSession: - qCDebug(IMAPRESOURCE_LOG) << "Cancelling this request. Probably there is no more session available."; - m_resource->cancelTask(i18n("There is currently no session to the IMAP server available.")); - break; - - case DeferIfNoSession: - qCDebug(IMAPRESOURCE_LOG) << "Defering this request. Probably there is no more session available."; - m_resource->deferTask(); - break; - } - - deleteLater(); - return; - } - - m_session = session; - - if (errorCode != SessionPool::NoError) { - Trace() << "Error on: " << metaObject()->className(); - switch (m_actionIfNoSession) { - case CancelIfNoSession: - qCDebug(IMAPRESOURCE_LOG) << "Cancelling this request. Probably there is no more session available."; - m_resource->cancelTask(i18n("There is currently no session to the IMAP server available.")); - break; - - case DeferIfNoSession: - qCDebug(IMAPRESOURCE_LOG) << "Defering this request. Probably there is no more session available."; - m_resource->deferTask(); - break; - } - - deleteLater(); + abortTask(errorString); return; } @@ -153,7 +129,7 @@ void ResourceTask::onConnectionLost(KIMAP::Session *session) // task is done m_session = nullptr; Trace() << metaObject()->className(); - cancelTask(i18n("Connection lost")); + abortTask(i18n("Connection lost")); } } @@ -165,7 +141,7 @@ void ResourceTask::onPoolDisconnect() m_pool = nullptr; Trace() << metaObject()->className(); - cancelTask(i18n("Connection lost")); + abortTask(i18n("Connection lost")); } QString ResourceTask::userName() const @@ -515,8 +491,7 @@ QList<QByteArray> ResourceTask::toAkonadiFlags(const QList<QByteArray> &flags) void ResourceTask::kill() { Trace() << metaObject()->className(); - qCDebug(IMAPRESOURCE_LOG); - cancelTask(i18n("killed")); + abortTask(i18n("killed")); } const QChar ResourceTask::separatorCharacter() const diff --git a/resources/imap/resourcetask.h b/resources/imap/resourcetask.h index 6b460ba27..142861192 100644 --- a/resources/imap/resourcetask.h +++ b/resources/imap/resourcetask.h @@ -145,6 +145,7 @@ protected: KIMAP::Acl::Rights myRights(const Akonadi::Collection &); private: + void abortTask(const QString &errorString); static QList<QByteArray> fromAkonadiFlags(const QList<QByteArray> &flags); -- 2.16.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor