mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-25 22:05:53 +03:00
SyncEngine: Refactor startSync() code
This commit is contained in:
parent
cb36a37779
commit
8b35cda4c6
2 changed files with 26 additions and 42 deletions
|
@ -525,54 +525,37 @@ void SyncEngine::startSync()
|
||||||
|
|
||||||
csync_resume(_csync_ctx);
|
csync_resume(_csync_ctx);
|
||||||
|
|
||||||
bool usingSelectiveSync = (!_selectiveSyncBlackList.isEmpty());
|
|
||||||
qDebug() << (usingSelectiveSync ? "====Using Selective Sync" : "====NOT Using Selective Sync");
|
|
||||||
|
|
||||||
int fileRecordCount = -1;
|
int fileRecordCount = -1;
|
||||||
if (!_journal->exists()) {
|
if (!_journal->exists()) {
|
||||||
fileRecordCount = _journal->getFileRecordCount(); // this creates the DB
|
qDebug() << "=====sync looks new (no DB exists)";
|
||||||
_journal->close(); // Close again so it doesn't interfere with the sync in the the other thread in csync_update
|
} else {
|
||||||
|
qDebug() << "=====sync with existing DB";
|
||||||
|
}
|
||||||
|
|
||||||
if( fileRecordCount == -1 ) {
|
fileRecordCount = _journal->getFileRecordCount(); // this creates the DB if it does not exist yet
|
||||||
// FIXME de-duplicate with logic below
|
bool isUpdateFrom_1_5 = _journal->isUpdateFrom_1_5();
|
||||||
qDebug() << "No way to create a sync journal!";
|
_journal->close(); // Close again so it doesn't interfere with the sync in the the other thread in csync_update
|
||||||
emit csyncError(tr("Unable to initialize a sync journal."));
|
|
||||||
finalize();
|
|
||||||
return;
|
|
||||||
// database creation error!
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
bool no_recursive_propfind = false;
|
||||||
csync_set_module_property(_csync_ctx, "no_recursive_propfind", &no_recursive_propfind);
|
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);
|
csync_set_userdata(_csync_ctx, this);
|
||||||
|
|
|
@ -99,6 +99,7 @@ bool SyncJournalDb::checkConnect()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The database file is created by this call (SQLITE_OPEN_CREATE)
|
||||||
if( !_db.open(_dbFile) ) {
|
if( !_db.open(_dbFile) ) {
|
||||||
QString error = _db.error();
|
QString error = _db.error();
|
||||||
qDebug() << "Error opening the db: " << error;
|
qDebug() << "Error opening the db: " << error;
|
||||||
|
|
Loading…
Reference in a new issue