mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-25 13:55:47 +03:00
Always wait on the thread before emiting finished
This ensure that there would be no way to have two thread running Refactor all the location where finished is called in a single function
This commit is contained in:
parent
7087dbc445
commit
bdba56f60b
2 changed files with 14 additions and 19 deletions
|
@ -66,6 +66,7 @@ SyncEngine::SyncEngine(CSYNC *ctx, const QString& localPath, const QString& remo
|
|||
qRegisterMetaType<SyncFileItem::Status>("SyncFileItem::Status");
|
||||
qRegisterMetaType<Progress::Info>("Progress::Info");
|
||||
|
||||
_thread.setObjectName("CSync_Neon_Thread");
|
||||
_thread.start();
|
||||
}
|
||||
|
||||
|
@ -414,10 +415,7 @@ void SyncEngine::handleSyncError(CSYNC *ctx, const char *state) {
|
|||
} else {
|
||||
emit csyncError(errStr);
|
||||
}
|
||||
csync_commit(_csync_ctx);
|
||||
emit finished();
|
||||
_syncMutex.unlock();
|
||||
_thread.quit();
|
||||
finalize();
|
||||
}
|
||||
|
||||
void SyncEngine::startSync()
|
||||
|
@ -451,12 +449,7 @@ void SyncEngine::startSync()
|
|||
if( fileRecordCount == -1 ) {
|
||||
qDebug() << "No way to create a sync journal!";
|
||||
emit csyncError(tr("Unable to initialize a sync journal."));
|
||||
|
||||
csync_commit(_csync_ctx);
|
||||
emit finished();
|
||||
_syncMutex.unlock();
|
||||
_thread.quit();
|
||||
|
||||
finalize();
|
||||
return;
|
||||
// database creation error!
|
||||
} else if ( fileRecordCount < 50 ) {
|
||||
|
@ -553,10 +546,7 @@ void SyncEngine::slotUpdateFinished(int updateResult)
|
|||
if (!_journal->isConnected()) {
|
||||
qDebug() << "Bailing out, DB failure";
|
||||
emit csyncError(tr("Cannot open the sync journal"));
|
||||
csync_commit(_csync_ctx);
|
||||
emit finished();
|
||||
_syncMutex.unlock();
|
||||
_thread.quit();
|
||||
finalize();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -570,10 +560,7 @@ void SyncEngine::slotUpdateFinished(int updateResult)
|
|||
emit aboutToRemoveAllFiles(_syncedItems.first()._direction, &cancel);
|
||||
if (cancel) {
|
||||
qDebug() << Q_FUNC_INFO << "Abort sync";
|
||||
csync_commit(_csync_ctx);
|
||||
emit finished();
|
||||
_syncMutex.unlock();
|
||||
_thread.quit();
|
||||
finalize();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -673,16 +660,21 @@ void SyncEngine::slotFinished()
|
|||
}
|
||||
_journal->commit("All Finished.", false);
|
||||
emit treeWalkResult(_syncedItems);
|
||||
finalize();
|
||||
}
|
||||
|
||||
void SyncEngine::finalize()
|
||||
{
|
||||
csync_commit(_csync_ctx);
|
||||
|
||||
qDebug() << "CSync run took " << _stopWatch.addLapTime(QLatin1String("Sync Finished"));
|
||||
_stopWatch.stop();
|
||||
|
||||
emit finished();
|
||||
_propagator.reset(0);
|
||||
_syncMutex.unlock();
|
||||
_thread.quit();
|
||||
_thread.wait();
|
||||
emit finished();
|
||||
}
|
||||
|
||||
void SyncEngine::slotProgress(const SyncFileItem& item, quint64 current)
|
||||
|
|
|
@ -101,6 +101,9 @@ private:
|
|||
int treewalkFile( TREE_WALK_FILE*, bool );
|
||||
bool checkBlacklisting( SyncFileItem *item );
|
||||
|
||||
// cleanup and emit the finished signal
|
||||
void finalize();
|
||||
|
||||
static QMutex _syncMutex;
|
||||
SyncFileItemVector _syncedItems;
|
||||
|
||||
|
|
Loading…
Reference in a new issue