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<SyncFileItem::Status>("SyncFileItem::Status");
|
||||||
qRegisterMetaType<Progress::Info>("Progress::Info");
|
qRegisterMetaType<Progress::Info>("Progress::Info");
|
||||||
|
|
||||||
|
_thread.setObjectName("CSync_Neon_Thread");
|
||||||
_thread.start();
|
_thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,10 +415,7 @@ void SyncEngine::handleSyncError(CSYNC *ctx, const char *state) {
|
||||||
} else {
|
} else {
|
||||||
emit csyncError(errStr);
|
emit csyncError(errStr);
|
||||||
}
|
}
|
||||||
csync_commit(_csync_ctx);
|
finalize();
|
||||||
emit finished();
|
|
||||||
_syncMutex.unlock();
|
|
||||||
_thread.quit();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SyncEngine::startSync()
|
void SyncEngine::startSync()
|
||||||
|
@ -451,12 +449,7 @@ void SyncEngine::startSync()
|
||||||
if( fileRecordCount == -1 ) {
|
if( fileRecordCount == -1 ) {
|
||||||
qDebug() << "No way to create a sync journal!";
|
qDebug() << "No way to create a sync journal!";
|
||||||
emit csyncError(tr("Unable to initialize a sync journal."));
|
emit csyncError(tr("Unable to initialize a sync journal."));
|
||||||
|
finalize();
|
||||||
csync_commit(_csync_ctx);
|
|
||||||
emit finished();
|
|
||||||
_syncMutex.unlock();
|
|
||||||
_thread.quit();
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
// database creation error!
|
// database creation error!
|
||||||
} else if ( fileRecordCount < 50 ) {
|
} else if ( fileRecordCount < 50 ) {
|
||||||
|
@ -553,10 +546,7 @@ void SyncEngine::slotUpdateFinished(int updateResult)
|
||||||
if (!_journal->isConnected()) {
|
if (!_journal->isConnected()) {
|
||||||
qDebug() << "Bailing out, DB failure";
|
qDebug() << "Bailing out, DB failure";
|
||||||
emit csyncError(tr("Cannot open the sync journal"));
|
emit csyncError(tr("Cannot open the sync journal"));
|
||||||
csync_commit(_csync_ctx);
|
finalize();
|
||||||
emit finished();
|
|
||||||
_syncMutex.unlock();
|
|
||||||
_thread.quit();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -570,10 +560,7 @@ void SyncEngine::slotUpdateFinished(int updateResult)
|
||||||
emit aboutToRemoveAllFiles(_syncedItems.first()._direction, &cancel);
|
emit aboutToRemoveAllFiles(_syncedItems.first()._direction, &cancel);
|
||||||
if (cancel) {
|
if (cancel) {
|
||||||
qDebug() << Q_FUNC_INFO << "Abort sync";
|
qDebug() << Q_FUNC_INFO << "Abort sync";
|
||||||
csync_commit(_csync_ctx);
|
finalize();
|
||||||
emit finished();
|
|
||||||
_syncMutex.unlock();
|
|
||||||
_thread.quit();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -673,16 +660,21 @@ void SyncEngine::slotFinished()
|
||||||
}
|
}
|
||||||
_journal->commit("All Finished.", false);
|
_journal->commit("All Finished.", false);
|
||||||
emit treeWalkResult(_syncedItems);
|
emit treeWalkResult(_syncedItems);
|
||||||
|
finalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SyncEngine::finalize()
|
||||||
|
{
|
||||||
csync_commit(_csync_ctx);
|
csync_commit(_csync_ctx);
|
||||||
|
|
||||||
qDebug() << "CSync run took " << _stopWatch.addLapTime(QLatin1String("Sync Finished"));
|
qDebug() << "CSync run took " << _stopWatch.addLapTime(QLatin1String("Sync Finished"));
|
||||||
_stopWatch.stop();
|
_stopWatch.stop();
|
||||||
|
|
||||||
emit finished();
|
|
||||||
_propagator.reset(0);
|
_propagator.reset(0);
|
||||||
_syncMutex.unlock();
|
_syncMutex.unlock();
|
||||||
_thread.quit();
|
_thread.quit();
|
||||||
|
_thread.wait();
|
||||||
|
emit finished();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SyncEngine::slotProgress(const SyncFileItem& item, quint64 current)
|
void SyncEngine::slotProgress(const SyncFileItem& item, quint64 current)
|
||||||
|
|
|
@ -101,6 +101,9 @@ private:
|
||||||
int treewalkFile( TREE_WALK_FILE*, bool );
|
int treewalkFile( TREE_WALK_FILE*, bool );
|
||||||
bool checkBlacklisting( SyncFileItem *item );
|
bool checkBlacklisting( SyncFileItem *item );
|
||||||
|
|
||||||
|
// cleanup and emit the finished signal
|
||||||
|
void finalize();
|
||||||
|
|
||||||
static QMutex _syncMutex;
|
static QMutex _syncMutex;
|
||||||
SyncFileItemVector _syncedItems;
|
SyncFileItemVector _syncedItems;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue