Checksum: Fix recomputation when forced in cfg file #3735
authorChristian Kamm <mail@ckamm.de>
Thu, 15 Oct 2015 07:54:01 +0000 (09:54 +0200)
committerChristian Kamm <mail@ckamm.de>
Wed, 28 Oct 2015 08:56:39 +0000 (09:56 +0100)
Don't recompute the checksum on each upload when the server does not
advertise supporting checksums.

src/libsync/capabilities.cpp
src/libsync/capabilities.h
src/libsync/propagateupload.cpp
src/libsync/transmissionchecksumvalidator.cpp
src/libsync/transmissionchecksumvalidator.h

index c6887c8db82c87e8f6a9857ec1b88e4beb4dbcbf..81f8d98461bc96258ffda16c8f137260784da56a 100644 (file)
@@ -13,6 +13,8 @@
 
 #include "capabilities.h"
 
+#include "configfile.h"
+
 #include <QVariantMap>
 
 namespace OCC {
@@ -63,9 +65,28 @@ bool Capabilities::shareResharing() const
     return _capabilities["files_sharing"].toMap()["resharing"].toBool();
 }
 
-QList<QByteArray> Capabilities::supportedChecksumTypes() const
+QList<QByteArray> Capabilities::supportedChecksumTypesRaw() const
 {
     return QList<QByteArray>();
 }
 
+QList<QByteArray> Capabilities::supportedChecksumTypes() const
+{
+    auto list = supportedChecksumTypesRaw();
+    QByteArray cfgType = ConfigFile().transmissionChecksum().toLatin1();
+    if (!cfgType.isEmpty()) {
+        list.prepend(cfgType);
+    }
+    return list;
+}
+
+QByteArray Capabilities::preferredChecksumType() const
+{
+    auto list = supportedChecksumTypes();
+    if (list.isEmpty()) {
+        return QByteArray();
+    }
+    return list.first();
+}
+
 }
index 28bcca6c0634f537042e478832f68fddf6912fa6..7f0984cc2e94873db9ff841bb55f423b4c861a16 100644 (file)
@@ -39,8 +39,16 @@ public:
     bool sharePublicLinkEnforceExpireDate() const;
     int  sharePublicLinkExpireDateDays() const;
     bool shareResharing() const;
+
+    /// Returns the checksum types the server explicitly advertises
+    QList<QByteArray> supportedChecksumTypesRaw() const;
+
+    /// Like supportedChecksumTypesRaw(), but includes the type from the config
     QList<QByteArray> supportedChecksumTypes() const;
 
+    /// Returns the checksum type that should be used for new uploads.
+    QByteArray preferredChecksumType() const;
+
 private:
     QVariantMap _capabilities;
 };
index a745d467534b1c52a4b174b7bf4a814eb83c6504..3412c0e29601905e4207c92e1796b3af4806455c 100644 (file)
@@ -227,17 +227,9 @@ void PropagateUploadFileQNAM::start()
 
     // Compute a new checksum.
     auto computeChecksum = new ComputeChecksum(this);
-
-    // If the config file does not specify a checksum type but the
-    // server supports it, choose a type based on that.
-    if (computeChecksum->checksumType().isEmpty()) {
-        if (!supportedChecksumTypes.isEmpty()) {
-            // TODO: We might want to prefer some types over others instead
-            // of choosing the first.
-            computeChecksum->setChecksumType(supportedChecksumTypes.first());
-        }
-    }
-    if (!uploadChecksumEnabled()) {
+    if (uploadChecksumEnabled()) {
+        computeChecksum->setChecksumType(_propagator->account()->capabilities().preferredChecksumType());
+    } else {
         computeChecksum->setChecksumType(QByteArray());
     }
 
index 21653fc51802f8afdec792d190969b3f882b5b77..1a0caaf763c8010a8d038200e18ee8ccf7d83fe4 100644 (file)
@@ -16,7 +16,6 @@
 #include "transmissionchecksumvalidator.h"
 #include "syncfileitem.h"
 #include "propagatorjobs.h"
-#include "configfile.h"
 #include "account.h"
 
 #include <qtconcurrentrun.h>
@@ -64,9 +63,6 @@ bool downloadChecksumEnabled()
 ComputeChecksum::ComputeChecksum(QObject* parent)
     : QObject(parent)
 {
-    // If the config file specifies a checksum type, use that.
-    ConfigFile cfg;
-    _checksumType = cfg.transmissionChecksum().toLatin1();
 }
 
 void ComputeChecksum::setChecksumType(const QByteArray& type)
index b8f10223f36ca2137ecb08228e90dd4d7114c2df..9ae1a1132f048de3a2cdf671e481a1277c89f8ea 100644 (file)
@@ -46,8 +46,7 @@ public:
     explicit ComputeChecksum(QObject* parent = 0);
 
     /**
-     * By default the checksum type is read from the config file, but can be overridden
-     * with this method.
+     * Sets the checksum type to be used. The default is empty.
      */
     void setChecksumType(const QByteArray& type);