]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
fix bulk upload of empty files
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Fri, 7 Jul 2023 09:18:46 +0000 (11:18 +0200)
committerMatthieu Gallien <matthieu_gallien@yahoo.fr>
Mon, 10 Jul 2023 08:38:39 +0000 (10:38 +0200)
force an empty body when we bulk upload empty files

force a "valid" checksum to be computed for empty files as bulk upload
server side expects a checksum even for empty files

Close #5824

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/common/checksumcalculator.cpp
src/libsync/putmultifilejob.cpp

index 588ff5e1c833d88a168e52a9ba2969b56707510b..016c7b09d9b1beb1b23d8abc565808644e9b89a0 100644 (file)
@@ -95,8 +95,6 @@ QByteArray ChecksumCalculator::calculate()
         return result;
     }
 
-    bool isAnyChunkAdded = false;
-
     for (;;) {
         QMutexLocker locker(&_deviceMutex);
         if (!_device->isOpen() || _device->atEnd()) {
@@ -114,7 +112,6 @@ QByteArray ChecksumCalculator::calculate()
         if (!addChunk(buf, sizeRead)) {
             break;
         }
-        isAnyChunkAdded = true;
     }
 
     {
@@ -124,14 +121,12 @@ QByteArray ChecksumCalculator::calculate()
         }
     }
 
-    if (isAnyChunkAdded) {
-        if (_algorithmType == AlgorithmType::Adler32) {
-            result = QByteArray::number(_adlerHash, 16);
-        } else {
-            Q_ASSERT(_cryptographicHash);
-            if (_cryptographicHash) {
-                result = _cryptographicHash->result().toHex();
-            }
+    if (_algorithmType == AlgorithmType::Adler32) {
+        result = QByteArray::number(_adlerHash, 16);
+    } else {
+        Q_ASSERT(_cryptographicHash);
+        if (_cryptographicHash) {
+            result = _cryptographicHash->result().toHex();
         }
     }
 
@@ -152,13 +147,6 @@ void ChecksumCalculator::initChecksumAlgorithm()
         return;
     }
 
-    {
-        QMutexLocker locker(&_deviceMutex);
-        if (_device->size() == 0) {
-            return;
-        }
-    }
-
     if (_algorithmType == AlgorithmType::Adler32) {
         _adlerHash = adler32(0L, Z_NULL, 0);
     } else {
index 05edda06a0516839264ea642bab2f0b27485e2d3..46b15f8b58ffa9e09df5bae611cf17459926ddea 100644 (file)
@@ -53,7 +53,11 @@ void PutMultiFileJob::start()
 
         auto onePart = QHttpPart{};
 
-        onePart.setBodyDevice(oneDevice._device.get());
+        if (oneDevice._device->size() == 0) {
+            onePart.setBody({});
+        } else {
+            onePart.setBodyDevice(oneDevice._device.get());
+        }
 
         for (auto it = oneDevice._headers.begin(); it != oneDevice._headers.end(); ++it) {
             onePart.setRawHeader(it.key(), it.value());