SyncEngine: make abort and closing more robust
authorOlivier Goffart <ogoffart@woboq.com>
Wed, 15 Jun 2016 15:01:00 +0000 (17:01 +0200)
committerOlivier Goffart <ogoffart@woboq.com>
Thu, 16 Jun 2016 06:26:33 +0000 (08:26 +0200)
We first need to set the abort flag to csync and then aborting the discovery
job, otherwise, the discovery thread could start a new job in the mean time.

We also need to make sure that the thread has existed before we destroy the
exclude list.

src/libsync/syncengine.cpp

index 36fefc0365f01370a520c1234d59b0937504f415..d71eba882c278284dd9deb17cc0bc698f8160082 100644 (file)
@@ -101,10 +101,10 @@ SyncEngine::SyncEngine(AccountPtr account, const QString& localPath,
 SyncEngine::~SyncEngine()
 {
     abort();
-    _excludedFiles.reset();
-    csync_destroy(_csync_ctx);
     _thread.quit();
     _thread.wait();
+    _excludedFiles.reset();
+    csync_destroy(_csync_ctx);
 }
 
 //Convert an error code from csync to a user readable string.
@@ -1379,13 +1379,13 @@ AccountPtr SyncEngine::account() const
 
 void SyncEngine::abort()
 {
+    // Sets a flag for the update phase
+    csync_request_abort(_csync_ctx);
     qDebug() << Q_FUNC_INFO << _discoveryMainThread;
     // Aborts the discovery phase job
     if (_discoveryMainThread) {
         _discoveryMainThread->abort();
     }
-    // Sets a flag for the update phase
-    csync_request_abort(_csync_ctx);
     // For the propagator
     if(_propagator) {
         _propagator->abort();