void SyncEngine::startSync() { Q_ASSERT(!_syncRunning); _syncRunning = true; if( ! _csync_ctx ) { qDebug() << "XXXXXXXXXXXXXXXX FAIL: do not have csync_ctx!"; } _syncedItems.clear(); _needsUpdate = false; csync_resume(_csync_ctx); if (!_journal->exists()) { qDebug() << "=====sync looks new (no DB exists), activating recursive PROPFIND if csync supports it"; 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. int fileRecordCount = 0; fileRecordCount = _journal->getFileRecordCount(); bool isUpdateFrom_1_5 = _journal->isUpdateFrom_1_5(); _journal->close(); 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! } 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); // TODO: This should be a part of this method, but we don't have // any way to get "session_key" module property from csync. Had we // have it, then we could keep this code and remove it from // AbstractCredentials implementations. if (Account *account = AccountManager::instance()->account()) { account->credentials()->syncContextPreStart(_csync_ctx); } else { qDebug() << Q_FUNC_INFO << "No default Account object, huh?"; } // if (_lastAuthCookies.length() > 0) { // // Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply // // when https://github.com/owncloud/core/pull/4042 is merged. // QString cookiesAsString; // foreach(QNetworkCookie c, _lastAuthCookies) { // cookiesAsString += c.name(); // cookiesAsString += '='; // cookiesAsString += c.value(); // cookiesAsString += "; "; // } // csync_set_module_property(_csync_ctx, "session_key", cookiesAsString.to // } // csync_set_auth_callback( _csync_ctx, getauth ); csync_set_log_callback( csyncLogCatcher ); //csync_set_log_level( 11 ); don't set the loglevel here, it shall be done by folder.cpp or owncloudcmd.cpp int timeout = OwncloudPropagator::httpTimeout(); csync_set_module_property(_csync_ctx, "timeout", &timeout); _stopWatch.start(); qDebug() << "#### Update start #################################################### >>"; UpdateJob *job = new UpdateJob(_csync_ctx); job->moveToThread(&_thread); connect(job, SIGNAL(finished(int)), this, SLOT(slotUpdateFinished(int))); QMetaObject::invokeMethod(job, "start", Qt::QueuedConnection); }
void CSyncThread::startSync() { if (!_syncMutex.tryLock()) { qDebug() << Q_FUNC_INFO << "WARNING: Another sync seems to be running. Not starting a new one."; return; } if( ! _csync_ctx ) { qDebug() << "XXXXXXXXXXXXXXXX FAIL: do not have csync_ctx!"; } qDebug() << Q_FUNC_INFO << "Sync started"; qDebug() << "starting to sync " << qApp->thread() << QThread::currentThread(); _syncedItems.clear(); _needsUpdate = false; csync_resume(_csync_ctx); if (!_journal->exists()) { qDebug() << "=====sync looks new (no DB exists), activating recursive PROPFIND if csync supports it"; 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. int fileRecordCount = 0; fileRecordCount = _journal->getFileRecordCount(); _journal->close(); if( fileRecordCount == -1 ) { qDebug() << "No way to create a sync journal!"; emit csyncError(tr("Unable to initialize a sync journal.")); csync_commit(_csync_ctx); emit finished(); _syncMutex.unlock(); _thread.quit(); 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"; } } csync_set_module_property(_csync_ctx, "csync_context", _csync_ctx); csync_set_userdata(_csync_ctx, this); // TODO: This should be a part of this method, but we don't have // any way to get "session_key" module property from csync. Had we // have it, then we could keep this code and remove it from // AbstractCredentials implementations. if (Account *account = AccountManager::instance()->account()) { account->credentials()->syncContextPreStart(_csync_ctx); } else { qDebug() << Q_FUNC_INFO << "No default Account object, huh?"; } // if (_lastAuthCookies.length() > 0) { // // Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply // // when https://github.com/owncloud/core/pull/4042 is merged. // QString cookiesAsString; // foreach(QNetworkCookie c, _lastAuthCookies) { // cookiesAsString += c.name(); // cookiesAsString += '='; // cookiesAsString += c.value(); // cookiesAsString += "; "; // } // csync_set_module_property(_csync_ctx, "session_key", cookiesAsString.to // } // csync_set_auth_callback( _csync_ctx, getauth ); csync_set_log_callback( csyncLogCatcher ); //csync_set_log_level( 11 ); don't set the loglevel here, it shall be done by folder.cpp or owncloudcmd.cpp _syncTime.start(); // Only used for the updater progress as we use the new propagator right now which does its own thing csync_set_progress_callback(_csync_ctx, csyncthread_updater_progress_callback); qDebug() << "#### Update start #################################################### >>"; UpdateJob *job = new UpdateJob(_csync_ctx); job->moveToThread(&_thread); connect(job, SIGNAL(finished(int)), this, SLOT(slotUpdateFinished(int))); QMetaObject::invokeMethod(job, "start", Qt::QueuedConnection); }