-
Notifications
You must be signed in to change notification settings - Fork 683
SyncEngine: Reads the data-fingerprint property #5056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -915,7 +915,16 @@ void SyncEngine::slotDiscoveryJobFinished(int discoveryResult) | |
| return; | ||
| } | ||
| } | ||
| if (!_hasForwardInTimeFiles && _backInTimeFiles >= 2) { | ||
|
|
||
| auto databaseFingerprint = _journal->dataFingerprint(); | ||
| // If databaseFingerprint is null, this means that there was no information in the database | ||
| // (for example, upgrading from a previous version, or first sync) | ||
| // Note that an empty ("") fingerprint is valid and means it was empty on the server before. | ||
| if (!databaseFingerprint.isNull() | ||
| && _discoveryMainThread->_dataFingerprint != databaseFingerprint) { | ||
| qDebug() << "data fingerprint changed, assume restore from backup" << databaseFingerprint << _discoveryMainThread->_dataFingerprint; | ||
| restoreOldFiles(); | ||
| } else if (!_hasForwardInTimeFiles && _backInTimeFiles >= 2) { | ||
| qDebug() << "All the changes are bringing files in the past, asking the user"; | ||
| // this typically happen when a backup is restored on the server | ||
| bool restore = false; | ||
|
|
@@ -958,7 +967,7 @@ void SyncEngine::slotDiscoveryJobFinished(int discoveryResult) | |
| this, SLOT(slotItemCompleted(const SyncFileItem &, const PropagatorJob &))); | ||
| connect(_propagator.data(), SIGNAL(progress(const SyncFileItem &,quint64)), | ||
| this, SLOT(slotProgress(const SyncFileItem &,quint64))); | ||
| connect(_propagator.data(), SIGNAL(finished()), this, SLOT(slotFinished()), Qt::QueuedConnection); | ||
| connect(_propagator.data(), SIGNAL(finished(bool)), this, SLOT(slotFinished(bool)), Qt::QueuedConnection); | ||
| connect(_propagator.data(), SIGNAL(seenLockedFile(QString)), SIGNAL(seenLockedFile(QString))); | ||
| connect(_propagator.data(), SIGNAL(touchedFile(QString)), SLOT(slotAddTouchedFile(QString))); | ||
|
|
||
|
|
@@ -1026,18 +1035,22 @@ void SyncEngine::slotItemCompleted(const SyncFileItem &item, const PropagatorJob | |
| emit itemCompleted(item, job); | ||
| } | ||
|
|
||
| void SyncEngine::slotFinished() | ||
| void SyncEngine::slotFinished(bool success) | ||
| { | ||
| _anotherSyncNeeded = _anotherSyncNeeded || _propagator->_anotherSyncNeeded; | ||
|
|
||
| if (success) { | ||
| _journal->setDataFingerprint(_discoveryMainThread->_dataFingerprint); | ||
| } | ||
|
|
||
| // emit the treewalk results. | ||
| if( ! _journal->postSyncCleanup( _seenFiles, _temporarilyUnavailablePaths ) ) { | ||
| qDebug() << "Cleaning of synced "; | ||
| } | ||
|
|
||
| _journal->commit("All Finished.", false); | ||
| emit treeWalkResult(_syncedItems); | ||
| finalize(true); // FIXME: should it be true if there was errors? | ||
| finalize(success); | ||
|
||
| } | ||
|
|
||
| void SyncEngine::finalize(bool success) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -286,6 +286,13 @@ bool SyncJournalDb::checkConnect() | |
| return sqlFail("Create table version", createQuery); | ||
| } | ||
|
|
||
| // create the checksumtype table. | ||
| createQuery.prepare("CREATE TABLE IF NOT EXISTS datafingerprint(" | ||
| "fingerprint TEXT UNIQUE" | ||
| ");"); | ||
| if (!createQuery.exec()) { | ||
| return sqlFail("Create table datafingerprint", createQuery); | ||
| } | ||
|
|
||
| createQuery.prepare("CREATE TABLE IF NOT EXISTS version(" | ||
| "major INTEGER(8)," | ||
|
|
@@ -436,6 +443,14 @@ bool SyncJournalDb::checkConnect() | |
| _insertChecksumTypeQuery.reset(new SqlQuery(_db)); | ||
| _insertChecksumTypeQuery->prepare("INSERT OR IGNORE INTO checksumtype (name) VALUES (?1)"); | ||
|
|
||
| _getDataFingerprintQuery.reset(new SqlQuery(_db)); | ||
| _getDataFingerprintQuery->prepare("SELECT fingerprint FROM datafingerprint"); | ||
|
|
||
| _setDataFingerprintQuery1.reset(new SqlQuery(_db)); | ||
| _setDataFingerprintQuery1->prepare("DELETE FROM datafingerprint;"); | ||
|
||
| _setDataFingerprintQuery2.reset(new SqlQuery(_db)); | ||
| _setDataFingerprintQuery2->prepare("INSERT INTO datafingerprint (fingerprint) VALUES (?1);"); | ||
|
|
||
| // don't start a new transaction now | ||
| commitInternal(QString("checkConnect End"), false); | ||
|
|
||
|
|
@@ -472,6 +487,9 @@ void SyncJournalDb::close() | |
| _getChecksumTypeIdQuery.reset(0); | ||
| _getChecksumTypeQuery.reset(0); | ||
| _insertChecksumTypeQuery.reset(0); | ||
| _getDataFingerprintQuery.reset(0); | ||
| _setDataFingerprintQuery1.reset(0); | ||
| _setDataFingerprintQuery2.reset(0); | ||
|
|
||
| _db.close(); | ||
| _avoidReadFromDbOnNextSyncFilter.clear(); | ||
|
|
@@ -1602,6 +1620,49 @@ int SyncJournalDb::mapChecksumType(const QByteArray& checksumType) | |
| return _getChecksumTypeIdQuery->intValue(0); | ||
| } | ||
|
|
||
| QByteArray SyncJournalDb::dataFingerprint() | ||
| { | ||
| QMutexLocker locker(&_mutex); | ||
| if (!checkConnect()) { | ||
| return QByteArray(); | ||
| } | ||
|
|
||
| _getDataFingerprintQuery->reset_and_clear_bindings(); | ||
| if (!_getDataFingerprintQuery->exec()) { | ||
| qWarning() << "Error SQL statement dataFingerprint: " | ||
| << _getDataFingerprintQuery->lastQuery() << " :" | ||
| << _getDataFingerprintQuery->error(); | ||
| return QByteArray(); | ||
| } | ||
|
|
||
| if (!_getDataFingerprintQuery->next()) { | ||
| return QByteArray(); | ||
| } | ||
| return _getDataFingerprintQuery->baValue(0); | ||
| } | ||
|
|
||
| void SyncJournalDb::setDataFingerprint(const QByteArray &dataFingerprint) | ||
| { | ||
| QMutexLocker locker(&_mutex); | ||
| if (!checkConnect()) { | ||
| return; | ||
| } | ||
|
|
||
| _setDataFingerprintQuery1->reset_and_clear_bindings(); | ||
| if (!_setDataFingerprintQuery1->exec()) { | ||
| qWarning() << "Error SQL statement setDataFingerprint1: " | ||
| << _setDataFingerprintQuery1->lastQuery() << " :" | ||
| << _setDataFingerprintQuery1->error(); | ||
| } | ||
|
|
||
| _setDataFingerprintQuery2->reset_and_clear_bindings(); | ||
| _setDataFingerprintQuery2->bindValue(1, dataFingerprint); | ||
| if (!_setDataFingerprintQuery2->exec()) { | ||
| qWarning() << "Error SQL statement setDataFingerprint2: " | ||
| << _setDataFingerprintQuery2->lastQuery() << " :" | ||
| << _setDataFingerprintQuery2->error(); | ||
| } | ||
| } | ||
|
|
||
| void SyncJournalDb::commit(const QString& context, bool startTrans) | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i still don't understand why there is a difference between empty and null. Why can't they be treated the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Null means there was no entry before.
Empty means there was one, and it was empty.
By default, on the server, it is empty.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. Weeeeird. But I guess this is because it was added later to the server
FYI @rullzer