From: Matthieu Gallien Date: Fri, 7 Jul 2023 09:18:46 +0000 (+0200) Subject: fix bulk upload of empty files X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~92^2^2~104^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=8cd1a30c400eab29f8bfd6b657f5ce6f232f3fb6;p=nextcloud-desktop.git fix bulk upload of empty files 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 --- diff --git a/src/common/checksumcalculator.cpp b/src/common/checksumcalculator.cpp index 588ff5e1c..016c7b09d 100644 --- a/src/common/checksumcalculator.cpp +++ b/src/common/checksumcalculator.cpp @@ -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 { diff --git a/src/libsync/putmultifilejob.cpp b/src/libsync/putmultifilejob.cpp index 05edda06a..46b15f8b5 100644 --- a/src/libsync/putmultifilejob.cpp +++ b/src/libsync/putmultifilejob.cpp @@ -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());