Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralex-z <blackslayer4@gmail.com>2021-12-20 12:13:48 +0300
committerallexzander (Rebase PR Action) <allexzander@users.noreply.github.com>2022-01-11 16:37:09 +0300
commitb7be10f712a5e4046f443460b95916abef9ebdae (patch)
treec58d8fa96eb19a0fda87edf7c7c7544762d000ed /src/common
parentfbe35538b667cf444645ed82ffa52f1a91a90809 (diff)
Ask server to recalculate checksum on validatin failure.
Signed-off-by: alex-z <blackslayer4@gmail.com>
Diffstat (limited to 'src/common')
-rw-r--r--src/common/checksums.cpp19
-rw-r--r--src/common/checksums.h14
2 files changed, 29 insertions, 4 deletions
diff --git a/src/common/checksums.cpp b/src/common/checksums.cpp
index 0c016ef4d..5cef55bfb 100644
--- a/src/common/checksums.cpp
+++ b/src/common/checksums.cpp
@@ -337,7 +337,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."));
+ emit validationFailed(tr("The checksum header is malformed."), ChecksumHeaderMalformed);
return nullptr;
}
@@ -360,15 +360,28 @@ void ValidateChecksumHeader::start(std::unique_ptr<QIODevice> device, const QByt
calculator->start(std::move(device));
}
+QByteArray ValidateChecksumHeader::calculatedChecksumType() const
+{
+ return _calculatedChecksumType;
+}
+
+QByteArray ValidateChecksumHeader::calculatedChecksum() const
+{
+ return _calculatedChecksum;
+}
+
void ValidateChecksumHeader::slotChecksumCalculated(const QByteArray &checksumType,
const QByteArray &checksum)
{
+ _calculatedChecksumType = checksumType;
+ _calculatedChecksum = checksum;
+
if (checksumType != _expectedChecksumType) {
- emit validationFailed(tr("The checksum header contained an unknown checksum type \"%1\"").arg(QString::fromLatin1(_expectedChecksumType)));
+ emit validationFailed(tr("The checksum header contained an unknown checksum type \"%1\"").arg(QString::fromLatin1(_expectedChecksumType)), ChecksumTypeUnknown);
return;
}
if (checksum != _expectedChecksum) {
- emit validationFailed(tr(R"(The downloaded file does not match the checksum, it will be resumed. "%1" != "%2")").arg(QString::fromUtf8(_expectedChecksum), QString::fromUtf8(checksum)));
+ emit validationFailed(tr(R"(The downloaded file does not match the checksum, it will be resumed. "%1" != "%2")").arg(QString::fromUtf8(_expectedChecksum), QString::fromUtf8(checksum)), ChecksumMismatch);
return;
}
emit validated(checksumType, checksum);
diff --git a/src/common/checksums.h b/src/common/checksums.h
index 351fa745d..80716040c 100644
--- a/src/common/checksums.h
+++ b/src/common/checksums.h
@@ -140,6 +140,12 @@ class OCSYNC_EXPORT ValidateChecksumHeader : public QObject
{
Q_OBJECT
public:
+ enum FailureReason {
+ Success,
+ ChecksumHeaderMalformed,
+ ChecksumTypeUnknown,
+ ChecksumMismatch,
+ };
explicit ValidateChecksumHeader(QObject *parent = nullptr);
/**
@@ -161,9 +167,12 @@ public:
*/
void start(std::unique_ptr<QIODevice> device, const QByteArray &checksumHeader);
+ QByteArray calculatedChecksumType() const;
+ QByteArray calculatedChecksum() const;
+
signals:
void validated(const QByteArray &checksumType, const QByteArray &checksum);
- void validationFailed(const QString &errMsg);
+ void validationFailed(const QString &errMsg, FailureReason reason);
private slots:
void slotChecksumCalculated(const QByteArray &checksumType, const QByteArray &checksum);
@@ -173,6 +182,9 @@ private:
QByteArray _expectedChecksumType;
QByteArray _expectedChecksum;
+
+ QByteArray _calculatedChecksumType;
+ QByteArray _calculatedChecksum;
};
/**