[Pkg-owncloud-commits] [owncloud-client] 71/103: Do not read from the database when upgrading from 1.5

Sandro Knauß hefee-guest at moszumanska.debian.org
Wed Apr 30 18:09:00 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 9da261acd88279ef3684d66ce3b740414f0c4974
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Fri Apr 25 13:31:44 2014 +0200

    Do not read from the database when upgrading from 1.5
    
    We need to make sure that the file id are updated (if the user
    had upgraded from owncloud 5 to owncloud 6 while using owncloud 1.5)
---
 csync/src/csync.c            |  9 +++++++++
 csync/src/csync.h            |  5 +++++
 csync/src/csync_private.h    |  1 +
 csync/src/csync_update.c     |  2 +-
 src/mirall/syncengine.cpp    |  7 +++++++
 src/mirall/syncjournaldb.cpp | 40 +++++++++++++++++++++++++++++++++++++++-
 src/mirall/syncjournaldb.h   |  7 +++++++
 src/mirall/theme.cpp         |  2 +-
 8 files changed, 70 insertions(+), 3 deletions(-)

diff --git a/csync/src/csync.c b/csync/src/csync.c
index 411826f..238334c 100644
--- a/csync/src/csync.c
+++ b/csync/src/csync.c
@@ -629,6 +629,8 @@ int csync_commit(CSYNC *ctx) {
   _csync_clean_ctx(ctx);
 
   ctx->remote.read_from_db = 0;
+  ctx->read_from_db_disabled = 0;
+
 
   /* Create new trees */
   rc = c_rbtree_create(&ctx->local.tree, _key_cmp, _data_cmp);
@@ -923,3 +925,10 @@ int csync_set_module_property(CSYNC* ctx, const char* key, void* value)
     return csync_vio_set_property(ctx, key, value);
 }
 
+
+int csync_set_read_from_db(CSYNC* ctx, int enabled)
+{
+    ctx->read_from_db_disabled = !enabled;
+    return 0;
+}
+
diff --git a/csync/src/csync.h b/csync/src/csync.h
index 49f3979..b692ef1 100644
--- a/csync/src/csync.h
+++ b/csync/src/csync.h
@@ -588,6 +588,11 @@ void csync_resume(CSYNC *ctx);
  */
 int  csync_abort_requested(CSYNC *ctx);
 
+/**
+ * Specify if it is allowed to read the remote tree from the DB (default to enabled)
+ */
+int csync_set_read_from_db(CSYNC* ctx, int enabled);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/csync/src/csync_private.h b/csync/src/csync_private.h
index a416de2..cfb642a 100644
--- a/csync/src/csync_private.h
+++ b/csync/src/csync_private.h
@@ -161,6 +161,7 @@ struct csync_s {
   int status;
   volatile int abort;
   void *rename_info;
+  int  read_from_db_disabled;
 };
 
 
diff --git a/csync/src/csync_update.c b/csync/src/csync_update.c
index 654b46a..0378e6a 100644
--- a/csync/src/csync_update.c
+++ b/csync/src/csync_update.c
@@ -255,7 +255,7 @@ static int _csync_detect_update(CSYNC *ctx, const char *file,
             goto out;
         }
         if (type == CSYNC_FTW_TYPE_DIR && ctx->current == REMOTE_REPLICA
-                && c_streq(fs->file_id, tmp->file_id)) {
+                && c_streq(fs->file_id, tmp->file_id) && !ctx->read_from_db_disabled) {
             /* If both etag and file id are equal for a directory, read all contents from
              * the database.
              * The comparison of file id ensure that we fetch all the file id when upgrading from
diff --git a/src/mirall/syncengine.cpp b/src/mirall/syncengine.cpp
index cf383aa..529744a 100644
--- a/src/mirall/syncengine.cpp
+++ b/src/mirall/syncengine.cpp
@@ -440,6 +440,7 @@ void SyncEngine::startSync()
         // csync_update also opens the database.
         int fileRecordCount = 0;
         fileRecordCount = _journal->getFileRecordCount();
+        bool isUpdateFrom_1_5 = _journal->isUpdateFrom_1_5();
         _journal->close();
 
         if( fileRecordCount == -1 ) {
@@ -460,6 +461,12 @@ void SyncEngine::startSync()
         } else {
             qDebug() << "=====sync with existing DB";
         }
+
+        if (fileRecordCount > 1 && isUpdateFrom_1_5) {
+            qDebug() << "detected update from 1.5";
+            // Disable the read from DB to be sure to re-read all the fileid and etags.
+            csync_set_read_from_db(_csync_ctx, false);
+        }
     }
 
     csync_set_module_property(_csync_ctx, "csync_context", _csync_ctx);
diff --git a/src/mirall/syncjournaldb.cpp b/src/mirall/syncjournaldb.cpp
index cb5d828..fe691eb 100644
--- a/src/mirall/syncjournaldb.cpp
+++ b/src/mirall/syncjournaldb.cpp
@@ -22,6 +22,7 @@
 #include "syncjournaldb.h"
 #include "syncjournalfilerecord.h"
 #include "utility.h"
+#include "version.h"
 
 #include "../../csync/src/std/c_jhash.h"
 
@@ -30,7 +31,7 @@
 namespace Mirall {
 
 SyncJournalDb::SyncJournalDb(const QString& path, QObject *parent) :
-    QObject(parent), _transaction(0)
+    QObject(parent), _transaction(0), _possibleUpgradeFromMirall_1_5(false)
 {
 
     _dbFile = path;
@@ -192,6 +193,35 @@ bool SyncJournalDb::checkConnect()
         return sqlFail("Create table blacklist", createQuery);
     }
 
+    createQuery.prepare("CREATE TABLE IF NOT EXISTS version("
+                               "major INTEGER(8),"
+                               "minor INTEGER(8),"
+                               "patch INTEGER(8),"
+                               "custom VARCHAR(256)"
+                               ");");
+    if (!createQuery.exec()) {
+        return sqlFail("Create table blacklist", createQuery);
+    }
+
+    QSqlQuery versionQuery("SELECT major, minor FROM version;", _db);
+    if (!versionQuery.next()) {
+        // If there was no entry in the table, it means we are likely upgrading from 1.5
+        _possibleUpgradeFromMirall_1_5 = true;
+    } else {
+        // Delete the existing entry so we can replace it by the new one
+        createQuery.prepare("DELETE FROM version;");
+        if (!createQuery.exec()) {
+            return sqlFail("Remove version", createQuery);
+        }
+    }
+    createQuery.prepare("INSERT INTO version (major, minor, patch) VALUES ( ? , ? , ? );");
+    createQuery.bindValue(0, MIRALL_VERSION_MAJOR);
+    createQuery.bindValue(1, MIRALL_VERSION_MINOR);
+    createQuery.bindValue(2, MIRALL_VERSION_PATCH);
+    if (!createQuery.exec()) {
+        return sqlFail("Insert Version", createQuery);
+    }
+
     commitInternal("checkConnect");
 
     bool rc = updateDatabaseStructure();
@@ -260,6 +290,7 @@ void SyncJournalDb::close()
     _deleteFileRecordPhash.reset(0);
     _deleteFileRecordRecursively.reset(0);
     _blacklistQuery.reset(0);
+    _possibleUpgradeFromMirall_1_5 = false;
 
     _db.close();
     _db = QSqlDatabase(); // avoid the warning QSqlDatabasePrivate::removeDatabase: connection [...] still in use
@@ -825,6 +856,13 @@ bool SyncJournalDb::isConnected()
     return checkConnect();
 }
 
+bool SyncJournalDb::isUpdateFrom_1_5()
+{
+    QMutexLocker lock(&_mutex);
+    checkConnect();
+    return _possibleUpgradeFromMirall_1_5;
+}
+
 
 
 } // namespace Mirall
diff --git a/src/mirall/syncjournaldb.h b/src/mirall/syncjournaldb.h
index b900423..899d5ed 100644
--- a/src/mirall/syncjournaldb.h
+++ b/src/mirall/syncjournaldb.h
@@ -85,6 +85,12 @@ public:
      */
     bool isConnected();
 
+    /**
+     * Tell the sync engine if we need to disable the fetch from db to be sure that the fileid
+     * are updated.
+     */
+    bool isUpdateFrom_1_5();
+
 
 
 
@@ -106,6 +112,7 @@ private:
     QString _dbFile;
     QMutex _mutex; // Public functions are protected with the mutex.
     int _transaction;
+    bool _possibleUpgradeFromMirall_1_5;
     QScopedPointer<QSqlQuery> _getFileRecordQuery;
     QScopedPointer<QSqlQuery> _setFileRecordQuery;
     QScopedPointer<QSqlQuery> _getDownloadInfoQuery;
diff --git a/src/mirall/theme.cpp b/src/mirall/theme.cpp
index 74a6cf4..3557a15 100644
--- a/src/mirall/theme.cpp
+++ b/src/mirall/theme.cpp
@@ -207,7 +207,7 @@ QString Theme::about() const
               "<p>Distributed by %4 and licensed under the GNU General Public License (GPL) Version 2.0.<br>"
               "%5 and the %5 logo are registered trademarks of %4 in the<br>"
               "United States, other countries, or both.</p>")
-            .arg(MIRALL_VERSION_STRING).arg("http://"MIRALL_STRINGIFY(APPLICATION_DOMAIN))
+            .arg(MIRALL_VERSION_MAJOR).arg("http://" MIRALL_STRINGIFY(APPLICATION_DOMAIN))
             .arg(MIRALL_STRINGIFY(APPLICATION_DOMAIN)).arg(APPLICATION_VENDOR).arg(APPLICATION_NAME);
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list