Checksums: Content checksums for all uploads #4375
authorChristian Kamm <mail@ckamm.de>
Wed, 2 Mar 2016 12:52:14 +0000 (13:52 +0100)
committerChristian Kamm <mail@ckamm.de>
Wed, 2 Mar 2016 13:28:20 +0000 (14:28 +0100)
src/libsync/checksums.cpp
src/libsync/checksums.h
src/libsync/propagateupload.cpp

index 1e4e29539f0af6fc44ccf79b21efdaef0c2ff131..99101fd244b1e9d8bbc35ea76a509b47fadfdccd 100644 (file)
@@ -114,6 +114,15 @@ bool downloadChecksumEnabled()
     return enabled;
 }
 
+QByteArray contentChecksumType()
+{
+    static QByteArray type = qgetenv("OWNCLOUD_CONTENT_CHECKSUM_TYPE");
+    if (!type.isNull()) { // can set to "" to disable checksumming
+        return type;
+    }
+    return "SHA1";
+}
+
 ComputeChecksum::ComputeChecksum(QObject* parent)
     : QObject(parent)
 {
index 30a040301b001d414071da0bebbd159a6892d7b0..519c74b71701507e3a37e6dbd13eeb78758360e4 100644 (file)
@@ -37,6 +37,10 @@ bool uploadChecksumEnabled();
 /// Checks OWNCLOUD_DISABLE_CHECKSUM_DOWNLOAD
 bool downloadChecksumEnabled();
 
+/// Checks OWNCLOUD_CONTENT_CHECKSUM_TYPE (default: SHA1)
+QByteArray contentChecksumType();
+
+
 /**
  * Computes the checksum of a file.
  * \ingroup libsync
index 1d76434cd33b9d8045d29e7c01e54912562c7424..896cd4125c3e46771276886f139c038ee053dc2e 100644 (file)
@@ -219,23 +219,18 @@ void PropagateUploadFileQNAM::slotComputeContentChecksum()
 
     _stopWatch.start();
 
-    QByteArray contentChecksumType;
-    // We currently only do content checksums for the particular .eml case
-    // This should be done more generally in the future!
-    if (filePath.endsWith(QLatin1String(".eml"), Qt::CaseInsensitive)) {
-        contentChecksumType = "MD5";
-    }
+    QByteArray checksumType = contentChecksumType();
 
     // Maybe the discovery already computed the checksum?
-    if (_item->_contentChecksumType == contentChecksumType
+    if (_item->_contentChecksumType == checksumType
             && !_item->_contentChecksum.isEmpty()) {
-        slotComputeTransmissionChecksum(contentChecksumType, _item->_contentChecksum);
+        slotComputeTransmissionChecksum(checksumType, _item->_contentChecksum);
         return;
     }
 
     // Compute the content checksum.
     auto computeChecksum = new ComputeChecksum(this);
-    computeChecksum->setChecksumType(contentChecksumType);
+    computeChecksum->setChecksumType(checksumType);
 
     connect(computeChecksum, SIGNAL(done(QByteArray,QByteArray)),
             SLOT(slotComputeTransmissionChecksum(QByteArray,QByteArray)));