Skip to content

Commit

Permalink
[buteo-sync-plugins-social] Prevent purge of deleted Google account c…
Browse files Browse the repository at this point in the history
…ontacts unless sync succeeds. Contributes to JB#38210
  • Loading branch information
Chris Adams committed Nov 16, 2018
1 parent 95b26f6 commit 1d28255
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions 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 @@ -824,6 +825,9 @@ void GoogleTwoWayContactSyncAdaptor::finalize(int accountId)
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 @@ -884,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 1d28255

Please sign in to comment.