Fix some error cases in the SyncEngine

Always cleanup properly when we bail out.

Also fix thread safety of the SyncJournalDB
This commit is contained in:
Olivier Goffart 2014-04-01 13:41:47 +02:00
parent ded21c5826
commit bfe6a50b19
3 changed files with 26 additions and 3 deletions

View file

@ -530,9 +530,12 @@ void SyncEngine::slotUpdateFinished(int updateResult)
}
// Sanity check
if (!_journal->checkConnect()) {
if (!_journal->isConnected()) {
qDebug() << "Bailing out, DB failure";
QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); // signal
emit csyncError(tr("Cannot open the sync journal"));
emit finished();
_syncMutex.unlock();
_thread.quit();
return;
}
@ -546,6 +549,9 @@ void SyncEngine::slotUpdateFinished(int updateResult)
emit aboutToRemoveAllFiles(_syncedItems.first()._direction, &cancel);
if (cancel) {
qDebug() << Q_FUNC_INFO << "Abort sync";
emit finished();
_syncMutex.unlock();
_thread.quit();
return;
}
}

View file

@ -819,5 +819,12 @@ SyncJournalDb::~SyncJournalDb()
close();
}
bool SyncJournalDb::isConnected()
{
QMutexLocker lock(&_mutex);
return checkConnect();
}
} // namespace Mirall

View file

@ -25,6 +25,11 @@ namespace Mirall {
class SyncJournalFileRecord;
class SyncJournalBlacklistRecord;
/**
* Class that handle the sync database
*
* This class is thread safe. All public function are locking the mutex.
*/
class SyncJournalDb : public QObject
{
Q_OBJECT
@ -75,7 +80,11 @@ public:
void close();
bool checkConnect();
/**
* return true if everything is correct
*/
bool isConnected();
@ -91,6 +100,7 @@ private:
void startTransaction();
void commitTransaction();
QStringList tableColumns( const QString& table );
bool checkConnect();
QSqlDatabase _db;
QString _dbFile;