diff --git a/src/common/checksums.cpp b/src/common/checksums.cpp index 79038554fc891..c604842a34e3b 100644 --- a/src/common/checksums.cpp +++ b/src/common/checksums.cpp @@ -328,7 +328,7 @@ ComputeChecksum *ValidateChecksumHeader::prepareStart(const QByteArray &checksum if (!parseChecksumHeader(checksumHeader, &_expectedChecksumType, &_expectedChecksum)) { qCWarning(lcChecksums) << "Checksum header malformed:" << checksumHeader; - emit validationFailed(tr("The checksum header is malformed."), {}, {}, _filePath); + emit validationFailed(tr("The checksum header is malformed.")); return nullptr; } @@ -341,7 +341,6 @@ ComputeChecksum *ValidateChecksumHeader::prepareStart(const QByteArray &checksum void ValidateChecksumHeader::start(const QString &filePath, const QByteArray &checksumHeader) { - _filePath = filePath; if (auto calculator = prepareStart(checksumHeader)) calculator->start(filePath); } @@ -356,11 +355,11 @@ void ValidateChecksumHeader::slotChecksumCalculated(const QByteArray &checksumTy const QByteArray &checksum) { if (checksumType != _expectedChecksumType) { - emit validationFailed(tr("The checksum header contained an unknown checksum type '%1'").arg(QString::fromLatin1(_expectedChecksumType)), {}, {}, _filePath); + emit validationFailed(tr("The checksum header contained an unknown checksum type '%1'").arg(QString::fromLatin1(_expectedChecksumType))); return; } if (checksum != _expectedChecksum) { - emit validationFailed(tr("The downloaded file does not match the checksum, it will be resumed. '%1' != '%2'").arg(QString::fromUtf8(_expectedChecksum), QString::fromUtf8(checksum)), checksumType, checksum, _filePath); + emit validationFailed(tr("The downloaded file does not match the checksum, it will be resumed. '%1' != '%2'").arg(QString::fromUtf8(_expectedChecksum), QString::fromUtf8(checksum))); return; } emit validated(checksumType, checksum); diff --git a/src/common/checksums.h b/src/common/checksums.h index 843017a431ea7..5c8d39d5c33e0 100644 --- a/src/common/checksums.h +++ b/src/common/checksums.h @@ -163,7 +163,7 @@ class OCSYNC_EXPORT ValidateChecksumHeader : public QObject signals: void validated(const QByteArray &checksumType, const QByteArray &checksum); - void validationFailed(const QString &errMsg, const QByteArray &checksumType, const QByteArray &checksum, const QString &filePath); + void validationFailed(const QString &errMsg); private slots: void slotChecksumCalculated(const QByteArray &checksumType, const QByteArray &checksum); @@ -173,8 +173,6 @@ private slots: QByteArray _expectedChecksumType; QByteArray _expectedChecksum; - - QString _filePath; }; /** diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index 24986f3cb00d6..ba5092729850c 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -50,7 +50,6 @@ #define DEFAULT_MAX_LOG_LINES 20000 namespace { -static constexpr char allowChecksumValidationFailC[] = "allowChecksumValidationFail"; static constexpr char showMainDialogAsNormalWindowC[] = "showMainDialogAsNormalWindow"; } @@ -892,11 +891,6 @@ void ConfigFile::setMoveToTrash(bool isChecked) setValue(moveToTrashC, isChecked); } -bool ConfigFile::allowChecksumValidationFail() const -{ - return getValue(allowChecksumValidationFailC, {}, false).toBool(); -} - bool ConfigFile::showMainDialogAsNormalWindow() const { return getValue(showMainDialogAsNormalWindowC, {}, false).toBool(); } diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h index 5f288bede8154..fb52c02c916d1 100644 --- a/src/libsync/configfile.h +++ b/src/libsync/configfile.h @@ -145,9 +145,6 @@ class OWNCLOUDSYNC_EXPORT ConfigFile bool moveToTrash() const; void setMoveToTrash(bool); - /** should we allow checksum validation to fail? set to true to workaround corrupted checksums **/ - bool allowChecksumValidationFail() const; - bool showMainDialogAsNormalWindow() const; static bool setConfDir(const QString &value); diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index 8fb05024b4502..f54e41c680354 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -28,8 +28,6 @@ #include "propagatedownloadencrypted.h" #include "common/vfs.h" -#include "configfile.h" - #include #include #include @@ -40,11 +38,6 @@ #include #endif -namespace { - constexpr quint16 numChecksumFailuresAllowed = 1; - constexpr char *checksumFailureDbRecordPrefix = "ChecksumValidationFailed_"; -} - namespace OCC { Q_LOGGING_CATEGORY(lcGetJob, "nextcloud.sync.networkjob.get", QtInfoMsg) @@ -830,38 +823,8 @@ void PropagateDownloadFile::slotGetFinished() validator->start(_tmpFile.fileName(), checksumHeader); } -void PropagateDownloadFile::slotChecksumFail(const QString &errMsg, const QByteArray &checksumType, const QByteArray &checksum, const QString &filePath) -{ - if (!checksumType.isEmpty() && !checksum.isEmpty() && !filePath.isEmpty()) { - ConfigFile cfgFile; - - if (cfgFile.allowChecksumValidationFail()) { - const auto key = QString(checksumFailureDbRecordPrefix + _item->_fileId); - const QStringList mismatchEntryForFileSplitted = propagator()->_journal->keyValueStoreGet(key).toString().split(":", QString::SkipEmptyParts); - const QByteArray mismatchChecksumForFile = mismatchEntryForFileSplitted.size() > 0 ? mismatchEntryForFileSplitted[0].toUtf8() : QByteArray(); - const auto numChecksumMismatchCases = mismatchEntryForFileSplitted.size() > 1 ? mismatchEntryForFileSplitted[1].toInt() : 0; - - // format must be CHECKSUM:COUNT - Q_ASSERT(mismatchEntryForFileSplitted.size() != 1); - if (mismatchEntryForFileSplitted.size() == 1) { - qCCritical(lcPropagateDownload) << "mismatchEntryForFile has incorrect format. Should be CHECKSUM:COUNT"; - } - - if (numChecksumMismatchCases < numChecksumFailuresAllowed || mismatchChecksumForFile != checksum) { - // not enough failures or different checksum this time - qCInfo(lcPropagateDownload) << "Checksum validation has failed" << numChecksumMismatchCases << " times, with previous checksum<" << mismatchChecksumForFile << "> and, current checksum<" << checksum << ">, but, allowChecksumValidationFail is set.Let's give it another try..."; - const auto numCasesToSet = mismatchChecksumForFile != checksum ? 1 : numChecksumMismatchCases + 1; - const QString value = QString::fromUtf8(checksum) + QStringLiteral(":") + QString::number(numCasesToSet); - propagator()->_journal->keyValueStoreSet(key, value); - } else { - propagator()->_journal->keyValueStoreDelete(key); - qCInfo(lcPropagateDownload) << "Checksum validation has failed" << numChecksumMismatchCases << " times, but, allowChecksumValidationFail is set, so, let's continue..."; - startContentChecksumCompute(checksumType, filePath); - return; - } - } - } - +void PropagateDownloadFile::slotChecksumFail(const QString &errMsg) +{ FileSystem::remove(_tmpFile.fileName()); propagator()->_anotherSyncNeeded = true; done(SyncFileItem::SoftError, errMsg); // tr("The file downloaded with a broken checksum, will be redownloaded.")); @@ -889,18 +852,6 @@ void PropagateDownloadFile::deleteExistingFolder() } } -void PropagateDownloadFile::startContentChecksumCompute(const QByteArray &checksumType, const QString &path) -{ - qCInfo(lcPropagateDownload) << "Start checksum compute with checksumType:" << checksumType << " for path:" << path; - // Compute the content checksum. - const auto computeChecksum = new ComputeChecksum(this); - computeChecksum->setChecksumType(checksumType); - - connect(computeChecksum, &ComputeChecksum::done, - this, &PropagateDownloadFile::contentChecksumComputed); - computeChecksum->start(path); -} - namespace { // Anonymous namespace for the recall feature static QString makeRecallFileName(const QString &fn) { @@ -989,9 +940,13 @@ void PropagateDownloadFile::transmissionChecksumValidated(const QByteArray &chec return contentChecksumComputed(checksumType, checksum); } - startContentChecksumCompute(theContentChecksumType, _tmpFile.fileName()); + // Compute the content checksum. + auto computeChecksum = new ComputeChecksum(this); + computeChecksum->setChecksumType(theContentChecksumType); - propagator()->_journal->keyValueStoreDelete(QString(checksumFailureDbRecordPrefix + _item->_fileId)); + connect(computeChecksum, &ComputeChecksum::done, + this, &PropagateDownloadFile::contentChecksumComputed); + computeChecksum->start(_tmpFile.fileName()); } void PropagateDownloadFile::contentChecksumComputed(const QByteArray &checksumType, const QByteArray &checksum) diff --git a/src/libsync/propagatedownload.h b/src/libsync/propagatedownload.h index 963bf1055a1aa..31f1749286a69 100644 --- a/src/libsync/propagatedownload.h +++ b/src/libsync/propagatedownload.h @@ -202,14 +202,12 @@ private slots: void abort(PropagatorJob::AbortType abortType) override; void slotDownloadProgress(qint64, qint64); - void slotChecksumFail(const QString &errMsg, const QByteArray &checksumType, const QByteArray &checksum, const QString &filePath); + void slotChecksumFail(const QString &errMsg); private: void startAfterIsEncryptedIsChecked(); void deleteExistingFolder(); - void startContentChecksumCompute(const QByteArray &checksumType, const QString &path); - qint64 _resumeStart; qint64 _downloadProgress; QPointer _job; diff --git a/test/testchecksumvalidator.cpp b/test/testchecksumvalidator.cpp index a7e07d85bdb1e..82c1b10704aa5 100644 --- a/test/testchecksumvalidator.cpp +++ b/test/testchecksumvalidator.cpp @@ -42,7 +42,8 @@ using namespace OCC::Utility; _successDown = true; } - void slotDownError(const QString &errMsg, const QByteArray&, const QByteArray&, const QString&) { + void slotDownError(const QString &errMsg) + { QCOMPARE(_expectedError, errMsg); _errorSeen = true; }