Close database after retrieval of file record count.

As the csync updater opens the database itself, it is cleaner to close
the db before and open it again after csync has finished.
Added a close method to the journal class.
This commit is contained in:
Klaas Freitag 2013-11-18 09:58:02 +01:00
parent 098e04c13f
commit e73730cb94
3 changed files with 42 additions and 6 deletions

View file

@ -345,17 +345,35 @@ void CSyncThread::startSync()
// maybe move this somewhere else where it can influence a running sync?
MirallConfigFile cfg;
int fileRecordCount = 0;
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 if ((fileRecordCount = _journal->getFileRecordCount()) < 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";
// 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);

View file

@ -170,6 +170,23 @@ bool SyncJournalDb::checkConnect()
return rc;
}
void SyncJournalDb::close()
{
QMutexLocker locker(&_mutex);
_getFileRecordQuery.reset(0);
_setFileRecordQuery.reset(0);
_getDownloadInfoQuery.reset(0);
_setDownloadInfoQuery.reset(0);
_deleteDownloadInfoQuery.reset(0);
_getUploadInfoQuery.reset(0);
_setUploadInfoQuery.reset(0);
_deleteUploadInfoQuery.reset(0);
_db.close();
}
bool SyncJournalDb::updateDatabaseStructure()
{
QStringList columns = tableColumns("metadata");

View file

@ -59,6 +59,7 @@ public:
void setUploadInfo(const QString &file, const UploadInfo &i);
bool postSyncCleanup( const QHash<QString, QString>& items );
void close();
signals:
public slots: