SyncEngine: Handle upgrade case from 1.8.0
authorKlaas Freitag <freitag@owncloud.com>
Mon, 4 May 2015 10:14:35 +0000 (12:14 +0200)
committerKlaas Freitag <freitag@owncloud.com>
Mon, 4 May 2015 11:40:25 +0000 (13:40 +0200)
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
src/libsync/syncjournaldb.cpp
src/libsync/syncjournaldb.h

index 81d0872972bb51f1db111a1e17779825f5c089b5..29be34ac5edbf7405495380f7434dc53980c124f 100644 (file)
@@ -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;
index 20d6eddf30fd990fc29efa89f57212053d57420f..2ff589a622c842a170abcd70a9721624e41b45ec 100644 (file)
@@ -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<QString>& 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)
 {
index eb3bc138f498ad1873036ed0b402c240739dc450..5fea8c1cdefdab5148b2cd0ed5cebc40f9431d03 100644 (file)
@@ -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<SqlQuery> _getFileRecordQuery;
     QScopedPointer<SqlQuery> _setFileRecordQuery;
     QScopedPointer<SqlQuery> _getDownloadInfoQuery;