Use the servers checksum type by default
authorHannah von Reth <hannah.vonreth@owncloud.com>
Fri, 24 Jul 2020 15:16:28 +0000 (17:16 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:59:16 +0000 (10:59 +0100)
src/common/checksums.cpp
src/common/checksums.h
src/libsync/capabilities.cpp
src/libsync/propagatedownload.cpp
src/libsync/propagateupload.cpp

index 462e2d3e5d8f7a8af711997c6e3e3becde7b7603..aef426813270d59b2b2c03662ef23c56bdf08eef 100644 (file)
@@ -189,15 +189,6 @@ bool uploadChecksumEnabled()
     return enabled;
 }
 
-QByteArray contentChecksumType()
-{
-    static QByteArray type = qgetenv("OWNCLOUD_CONTENT_CHECKSUM_TYPE");
-    if (type.isNull()) { // can set to "" to disable checksumming
-        type = "SHA1";
-    }
-    return type;
-}
-
 static bool checksumComputationEnabled()
 {
     static bool enabled = qEnvironmentVariableIsEmpty("OWNCLOUD_DISABLE_CHECKSUM_COMPUTATIONS");
index 1e5151c7a0d553e176621aa1ee05c3bd2b5882b8..5c8d39d5c33e09167baaac0b2fb43a61a0b1722c 100644 (file)
@@ -65,9 +65,6 @@ OCSYNC_EXPORT QByteArray parseChecksumHeaderType(const QByteArray &header);
 /// Checks OWNCLOUD_DISABLE_CHECKSUM_UPLOAD
 OCSYNC_EXPORT bool uploadChecksumEnabled();
 
-/// Checks OWNCLOUD_CONTENT_CHECKSUM_TYPE (default: SHA1)
-OCSYNC_EXPORT QByteArray contentChecksumType();
-
 // Exported functions for the tests.
 QByteArray OCSYNC_EXPORT calcMd5(QIODevice *device);
 QByteArray OCSYNC_EXPORT calcSha1(QIODevice *device);
index 1ea4a58dca39ef5003cc482a4e87f1def7f2ee1e..04600601d8a4277560b5e09c400d4536e4aa7c80 100644 (file)
@@ -150,7 +150,9 @@ QList<QByteArray> Capabilities::supportedChecksumTypes() const
 
 QByteArray Capabilities::preferredUploadChecksumType() const
 {
-    return _capabilities["checksums"].toMap()["preferredUploadType"].toByteArray();
+    return qEnvironmentVariable("OWNCLOUD_CONTENT_CHECKSUM_TYPE",
+                                _capabilities.value(QStringLiteral("checksums")).toMap()
+                                .value(QStringLiteral("preferredUploadType"), QStringLiteral("SHA1")).toString()).toUtf8();
 }
 
 QByteArray Capabilities::uploadChecksumType() const
index b630778c8d156648a0052dde8be145d6da776f9e..99ee0fe055dfc88d228cec24b5c778b192cd98c1 100644 (file)
@@ -909,7 +909,7 @@ namespace { // Anonymous namespace for the recall feature
 
 void PropagateDownloadFile::transmissionChecksumValidated(const QByteArray &checksumType, const QByteArray &checksum)
 {
-    const auto theContentChecksumType = contentChecksumType();
+    const QByteArray theContentChecksumType = propagator()->account()->capabilities().preferredUploadChecksumType();
 
     // Reuse transmission checksum as content checksum.
     //
index 14c6416d3debc2ed2c26b872ce5b9fc7434685f5..f64ef03a3cf9c908af201521db18c26b6a626f1b 100644 (file)
@@ -349,7 +349,7 @@ void PropagateUploadFileCommon::slotComputeContentChecksum()
     // probably temporary one.
     _item->_modtime = FileSystem::getModTime(filePath);
 
-    QByteArray checksumType = contentChecksumType();
+    const QByteArray checksumType = propagator()->account()->capabilities().preferredUploadChecksumType();
 
     // Maybe the discovery already computed the checksum?
     // Should I compute the checksum of the original (_item->_file)