Checksums: keep the transfer checksum in the database as the content checksum
authorOlivier Goffart <ogoffart@woboq.com>
Thu, 25 Feb 2016 16:17:14 +0000 (17:17 +0100)
committerOlivier Goffart <ogoffart@woboq.com>
Thu, 25 Feb 2016 16:17:14 +0000 (17:17 +0100)
Currently, we only use this for .eml files. But we can just store this checksum
in the database if it was computed anyway.

Issue #4487

src/libsync/propagatedownload.cpp
src/libsync/propagatedownload.h
src/libsync/propagateupload.cpp

index dfc27951193237646c0bca625a6b2828313611a6..c599ea1e80e528adca3539939c2d7392021d7f98 100644 (file)
@@ -550,7 +550,7 @@ void PropagateDownloadFileQNAM::slotGetFinished()
     // as this is (still) also correct.
     ValidateChecksumHeader *validator = new ValidateChecksumHeader(this);
     connect(validator, SIGNAL(validated(QByteArray,QByteArray)),
-            SLOT(downloadFinished()));
+            SLOT(downloadFinished(QByteArray,QByteArray)));
     connect(validator, SIGNAL(validationFailed(QString)),
             SLOT(slotChecksumFail(QString)));
     auto checksumHeader = job->reply()->rawHeader(checkSumHeaderC);
@@ -638,8 +638,13 @@ static void handleRecallFile(const QString &fn)
 }
 } // end namespace
 
-void PropagateDownloadFileQNAM::downloadFinished()
+void PropagateDownloadFileQNAM::downloadFinished(const QByteArray& transportChecksumType,
+                                                 const QByteArray& transportChecksum)
 {
+    // by default, reuse the transport checksum as content checksum
+    _item->_contentChecksum = transportChecksum;
+    _item->_contentChecksumType = transportChecksumType;
+
     QString fn = _propagator->getFilePath(_item->_file);
 
     // In case of file name clash, report an error
index 8ba11f1b5dbd48127b085f91404f649699cfdaff..ba70d2a999fc060901105231d89bd8dc6f3c0ae8 100644 (file)
@@ -128,7 +128,8 @@ public:
 private slots:
     void slotGetFinished();
     void abort() Q_DECL_OVERRIDE;
-    void downloadFinished();
+    void downloadFinished(const QByteArray& transportChecksumType = QByteArray(),
+                          const QByteArray &transportChecksum = QByteArray());
     void slotDownloadProgress(qint64,qint64);
     void slotChecksumFail( const QString& errMsg );
 
index 92439b6a46d2901890e1a5d10f24bbde7c23f2a7..1d76434cd33b9d8045d29e7c01e54912562c7424 100644 (file)
@@ -282,6 +282,12 @@ void PropagateUploadFileQNAM::slotStartUpload(const QByteArray& transmissionChec
     _transmissionChecksum = transmissionChecksum;
     _transmissionChecksumType = transmissionChecksumType;
 
+    if (_item->_contentChecksum.isEmpty() && _item->_contentChecksumType.isEmpty())  {
+        // If the _contentChecksum was not set, reuse the transmission checksum as the content checksum.
+        _item->_contentChecksum = transmissionChecksum;
+        _item->_contentChecksumType = transmissionChecksumType;
+    }
+
     const QString fullFilePath = _propagator->getFilePath(_item->_file);
 
     if (!FileSystem::fileExists(fullFilePath)) {