Skip to content

Commit

Permalink
Merge branch 'jb38210' into 'master'
Browse files Browse the repository at this point in the history
[buteo-sync-plugins-social] Early-out finalize() for Google Contacts in error case. Contributes to JB#38210

See merge request mer-core/buteo-sync-plugins-social!30
  • Loading branch information
rainemak committed Nov 16, 2018
2 parents 9db57f3 + 1d28255 commit 6ac4962
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/google/google-contacts/googletwowaycontactsyncadaptor.cpp
Expand Up @@ -69,6 +69,7 @@ GoogleTwoWayContactSyncAdaptor::GoogleTwoWayContactSyncAdaptor(QObject *parent)
: GoogleDataTypeSyncAdaptor(SocialNetworkSyncAdaptor::Contacts, parent)
, QtContactsSqliteExtensions::TwoWayContactSyncAdapter(QStringLiteral("google"))
, m_workerObject(new GoogleContactImageDownloader())
, m_allowFinalCleanup(false)
{
connect(m_workerObject, &AbstractImageDownloader::imageDownloaded,
this, &GoogleTwoWayContactSyncAdaptor::imageDownloaded);
Expand Down Expand Up @@ -815,13 +816,18 @@ void GoogleTwoWayContactSyncAdaptor::purgeAccount(int pid)

void GoogleTwoWayContactSyncAdaptor::finalize(int accountId)
{
if (m_accessTokens[accountId].isEmpty() || syncAborted()) {
if (m_accessTokens[accountId].isEmpty()
|| syncAborted()
|| status() == SocialNetworkSyncAdaptor::Error) {
// account failure occurred before sync process was started,
// or other error occurred during sync.
// in this case we have nothing left to do except cleanup.
return;
}

// sync was successful, allow cleaning up contacts from removed accounts.
m_allowFinalCleanup = true;

// first, ensure we update any avatars required.
if (m_downloadedContactAvatars[accountId].size()) {
// find the contacts we need to update from our mutated prev remote list.
Expand Down Expand Up @@ -882,6 +888,15 @@ void GoogleTwoWayContactSyncAdaptor::finalize(int accountId)

void GoogleTwoWayContactSyncAdaptor::finalCleanup()
{
// Only perform the cleanup if the sync cycle was successful.
// Note: purgeDataForOldAccount() will still be invoked by Buteo
// in response to the account being deleted when restoring the
// backup, so we cannot avoid the problem of "lost contacts"
// completely. See JB#38210 for more information.
if (!m_allowFinalCleanup) {
return;
}

// Synchronously find any contacts which need to be removed,
// which were somehow "left behind" by the sync process.
// Also, determine if any avatars were not synced, and remove those details.
Expand Down
2 changes: 2 additions & 0 deletions src/google/google-contacts/googletwowaycontactsyncadaptor.h
Expand Up @@ -117,6 +117,8 @@ private Q_SLOTS:
QMap<int, int> m_apiRequestsRemaining;
QMap<int, QMap<QString, QString> > m_queuedAvatarsForDownload; // contact guid -> remote avatar path
QMap<int, QMap<QString, QString> > m_downloadedContactAvatars; // contact guid -> local file path

bool m_allowFinalCleanup;
};

#endif // GOOGLETWOWAYCONTACTSYNCADAPTOR_H

0 comments on commit 6ac4962

Please sign in to comment.