From 8b35cda4c683a68830c216056cff98b3e15fef3f Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Mon, 20 Oct 2014 15:51:50 +0200 Subject: [PATCH] SyncEngine: Refactor startSync() code --- src/mirall/syncengine.cpp | 67 ++++++++++++++---------------------- src/mirall/syncjournaldb.cpp | 1 + 2 files changed, 26 insertions(+), 42 deletions(-) diff --git a/src/mirall/syncengine.cpp b/src/mirall/syncengine.cpp index 895186606..f507d69a4 100644 --- a/src/mirall/syncengine.cpp +++ b/src/mirall/syncengine.cpp @@ -525,54 +525,37 @@ void SyncEngine::startSync() csync_resume(_csync_ctx); - bool usingSelectiveSync = (!_selectiveSyncBlackList.isEmpty()); - qDebug() << (usingSelectiveSync ? "====Using Selective Sync" : "====NOT Using Selective Sync"); - int fileRecordCount = -1; if (!_journal->exists()) { - fileRecordCount = _journal->getFileRecordCount(); // this creates the DB - _journal->close(); // Close again so it doesn't interfere with the sync in the the other thread in csync_update + qDebug() << "=====sync looks new (no DB exists)"; + } else { + qDebug() << "=====sync with existing DB"; + } - if( fileRecordCount == -1 ) { - // FIXME de-duplicate with logic below - qDebug() << "No way to create a sync journal!"; - emit csyncError(tr("Unable to initialize a sync journal.")); - finalize(); - return; - // database creation error! - } + fileRecordCount = _journal->getFileRecordCount(); // this creates the DB if it does not exist yet + bool isUpdateFrom_1_5 = _journal->isUpdateFrom_1_5(); + _journal->close(); // Close again so it doesn't interfere with the sync in the the other thread in csync_update - qDebug() << "=====sync looks new (no DB exists), activating recursive PROPFIND if csync supports it"; + if( fileRecordCount == -1 ) { + qDebug() << "No way to create a sync journal!"; + emit csyncError(tr("Unable to initialize a sync journal.")); + finalize(); + return; + // database creation error! + } + + 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); + } + + bool usingSelectiveSync = (!_selectiveSyncBlackList.isEmpty()); + qDebug() << (usingSelectiveSync ? "====Using Selective Sync" : "====NOT Using Selective Sync"); + if (fileRecordCount >= 0 && fileRecordCount < 50 && !usingSelectiveSync) { + qDebug() << "===== Activating recursive PROPFIND (currently" << fileRecordCount << "file records)"; bool no_recursive_propfind = false; csync_set_module_property(_csync_ctx, "no_recursive_propfind", &no_recursive_propfind); - } else { - // retrieve the file count from the db and close it afterwards because - // csync_update also opens the database. - - fileRecordCount = _journal->getFileRecordCount(); - bool isUpdateFrom_1_5 = _journal->isUpdateFrom_1_5(); - _journal->close(); - - if( fileRecordCount == -1 ) { - // FIXME de-duplicate with logic above - qDebug() << "No way to create a sync journal!"; - emit csyncError(tr("Unable to initialize a sync journal.")); - finalize(); - return; - // database creation error! - } else if ( fileRecordCount < 50 ) { - qDebug() << "=====sync DB has only" << fileRecordCount << "items, enable recursive PROPFIND if csync supports it"; - bool no_recursive_propfind = false; - csync_set_module_property(_csync_ctx, "no_recursive_propfind", &no_recursive_propfind); - } 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_userdata(_csync_ctx, this); diff --git a/src/mirall/syncjournaldb.cpp b/src/mirall/syncjournaldb.cpp index 3a07869eb..c19d16c96 100644 --- a/src/mirall/syncjournaldb.cpp +++ b/src/mirall/syncjournaldb.cpp @@ -99,6 +99,7 @@ bool SyncJournalDb::checkConnect() return false; } + // The database file is created by this call (SQLITE_OPEN_CREATE) if( !_db.open(_dbFile) ) { QString error = _db.error(); qDebug() << "Error opening the db: " << error;