From d63abef718ebab0717c496dca11a9ad363bf6965 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Mon, 4 May 2015 12:14:35 +0200 Subject: [PATCH] SyncEngine: Handle upgrade case from 1.8.0 If 1.8.0 caused missing data in the local tree, this patch gets it back. For that, the usage of the journal for remote repository is disabled at the first start. --- src/libsync/syncengine.cpp | 9 ++++++++- src/libsync/syncjournaldb.cpp | 16 ++++++++++++++++ src/libsync/syncjournaldb.h | 2 ++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp index 81d087297..29be34ac5 100644 --- a/src/libsync/syncengine.cpp +++ b/src/libsync/syncengine.cpp @@ -605,7 +605,14 @@ void SyncEngine::startSync() // database creation error! } - if (fileRecordCount >= 1 && isUpdateFrom_1_5) { + bool isUpdateFrom_1_8 = _journal->isUpdateFrom_1_8_0(); + + /* + * If 1.8.0 caused missing data in the local tree, this patch gets it + * back. For that, the usage of the journal for remote repository is + * disabled at the first start. + */ + if (fileRecordCount >= 1 && (isUpdateFrom_1_5 || isUpdateFrom_1_8)) { qDebug() << "detected update from 1.5" << fileRecordCount << isUpdateFrom_1_5; // Disable the read from DB to be sure to re-read all the fileid and etags. _csync_ctx->read_remote_from_db = false; diff --git a/src/libsync/syncjournaldb.cpp b/src/libsync/syncjournaldb.cpp index 20d6eddf3..2ff589a62 100644 --- a/src/libsync/syncjournaldb.cpp +++ b/src/libsync/syncjournaldb.cpp @@ -273,6 +273,8 @@ bool SyncJournalDb::checkConnect() } _possibleUpgradeFromMirall_1_5 = false; + _possibleUpgradeFromMirall_1_8_0 = false; + SqlQuery versionQuery("SELECT major, minor, patch FROM version;", _db); if (!versionQuery.next()) { // If there was no entry in the table, it means we are likely upgrading from 1.5 @@ -292,6 +294,9 @@ bool SyncJournalDb::checkConnect() int minor = versionQuery.intValue(1); int patch = versionQuery.intValue(2); + if( major == 1 && minor == 8 && patch == 0 ) { + _possibleUpgradeFromMirall_1_8_0 = true; + } // Not comparing the BUILD id here, correct? if( !(major == MIRALL_VERSION_MAJOR && minor == MIRALL_VERSION_MINOR && patch == MIRALL_VERSION_PATCH) ) { createQuery.prepare("UPDATE version SET major=?1, minor=?2, patch =?3, custom=?4 " @@ -753,6 +758,10 @@ bool SyncJournalDb::postSyncCleanup(const QSet& filepathsToKeep, _possibleUpgradeFromMirall_1_5 = false; // should be handled now } + if (_possibleUpgradeFromMirall_1_8_0) { + _possibleUpgradeFromMirall_1_8_0 = false; // should be handled now + } + return true; } @@ -1322,6 +1331,13 @@ bool SyncJournalDb::isUpdateFrom_1_5() return _possibleUpgradeFromMirall_1_5; } +bool SyncJournalDb::isUpdateFrom_1_8_0() +{ + QMutexLocker lock(&_mutex); + checkConnect(); + return _possibleUpgradeFromMirall_1_8_0; +} + bool operator==(const SyncJournalDb::DownloadInfo & lhs, const SyncJournalDb::DownloadInfo & rhs) { diff --git a/src/libsync/syncjournaldb.h b/src/libsync/syncjournaldb.h index eb3bc138f..5fea8c1cd 100644 --- a/src/libsync/syncjournaldb.h +++ b/src/libsync/syncjournaldb.h @@ -118,6 +118,7 @@ public: * are updated. */ bool isUpdateFrom_1_5(); + bool isUpdateFrom_1_8_0(); private: bool updateDatabaseStructure(); @@ -135,6 +136,7 @@ private: QMutex _mutex; // Public functions are protected with the mutex. int _transaction; bool _possibleUpgradeFromMirall_1_5; + bool _possibleUpgradeFromMirall_1_8_0; QScopedPointer _getFileRecordQuery; QScopedPointer _setFileRecordQuery; QScopedPointer _getDownloadInfoQuery;