Skip to content

Commit 8cd1a30

Browse files
committed
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 <matthieu.gallien@nextcloud.com>
1 parent 0bb0491 commit 8cd1a30

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

src/common/checksumcalculator.cpp

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ QByteArray ChecksumCalculator::calculate()
9595
return result;
9696
}
9797

98-
bool isAnyChunkAdded = false;
99-
10098
for (;;) {
10199
QMutexLocker locker(&_deviceMutex);
102100
if (!_device->isOpen() || _device->atEnd()) {
@@ -114,7 +112,6 @@ QByteArray ChecksumCalculator::calculate()
114112
if (!addChunk(buf, sizeRead)) {
115113
break;
116114
}
117-
isAnyChunkAdded = true;
118115
}
119116

120117
{
@@ -124,14 +121,12 @@ QByteArray ChecksumCalculator::calculate()
124121
}
125122
}
126123

127-
if (isAnyChunkAdded) {
128-
if (_algorithmType == AlgorithmType::Adler32) {
129-
result = QByteArray::number(_adlerHash, 16);
130-
} else {
131-
Q_ASSERT(_cryptographicHash);
132-
if (_cryptographicHash) {
133-
result = _cryptographicHash->result().toHex();
134-
}
124+
if (_algorithmType == AlgorithmType::Adler32) {
125+
result = QByteArray::number(_adlerHash, 16);
126+
} else {
127+
Q_ASSERT(_cryptographicHash);
128+
if (_cryptographicHash) {
129+
result = _cryptographicHash->result().toHex();
135130
}
136131
}
137132

@@ -152,13 +147,6 @@ void ChecksumCalculator::initChecksumAlgorithm()
152147
return;
153148
}
154149

155-
{
156-
QMutexLocker locker(&_deviceMutex);
157-
if (_device->size() == 0) {
158-
return;
159-
}
160-
}
161-
162150
if (_algorithmType == AlgorithmType::Adler32) {
163151
_adlerHash = adler32(0L, Z_NULL, 0);
164152
} else {

src/libsync/putmultifilejob.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ void PutMultiFileJob::start()
5353

5454
auto onePart = QHttpPart{};
5555

56-
onePart.setBodyDevice(oneDevice._device.get());
56+
if (oneDevice._device->size() == 0) {
57+
onePart.setBody({});
58+
} else {
59+
onePart.setBodyDevice(oneDevice._device.get());
60+
}
5761

5862
for (auto it = oneDevice._headers.begin(); it != oneDevice._headers.end(); ++it) {
5963
onePart.setRawHeader(it.key(), it.value());

0 commit comments

Comments
 (0)