Skip to content

Commit

Permalink
libsync: Fix checksum and size for symlinks in bulk upload
Browse files Browse the repository at this point in the history
  • Loading branch information
taminob committed Nov 15, 2023
1 parent 4a19149 commit 0e645eb
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/libsync/bulkpropagatorjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ void BulkPropagatorJob::triggerUpload()
0,
std::numeric_limits<qint64>::max(),
&propagator()->_bandwidthManager);
singleFile._headers["Content-Length"] = QByteArray::number(device->size());
} else {
device = std::make_unique<UploadDevice>(singleFile._localPath,
0,
Expand All @@ -234,7 +233,7 @@ void BulkPropagatorJob::triggerUpload()
}

singleFile._headers["X-File-Path"] = singleFile._remotePath.toUtf8();
singleFile._headers["X-File-Type"] = QString::number(singleFile._item->_type == ItemTypeSoftLink).toUtf8();
singleFile._headers["OC-File-Type"] = QString::number(singleFile._item->_type).toUtf8();
uploadParametersData.push_back({std::move(device), singleFile._headers});
timeout += singleFile._fileSize;
}
Expand Down Expand Up @@ -282,12 +281,24 @@ void BulkPropagatorJob::slotComputeTransmissionChecksum(SyncFileItemPtr item,
const auto checksumType = uploadChecksumEnabled() ? "MD5" : "";
computeChecksum->setChecksumType(checksumType);

connect(computeChecksum, &ComputeChecksum::done, this, [this, item, fileToUpload] (const QByteArray &contentChecksumType, const QByteArray &contentChecksum) {
slotStartUpload(item, fileToUpload, contentChecksumType, contentChecksum);
});
connect(computeChecksum, &ComputeChecksum::done, computeChecksum, &QObject::deleteLater);
if (item->_type == CSyncEnums::ItemTypeSoftLink) {
auto checksumDevice = QSharedPointer<SymLinkUploadDevice>::create(fileToUpload._path,
0,
std::numeric_limits<qint64>::max(),
&propagator()->_bandwidthManager);
const auto contentChecksum = ComputeChecksum().computeNow(checksumDevice, checksumType);
item->_size = checksumDevice->size();
fileToUpload._size = checksumDevice->size();
slotStartUpload(item, fileToUpload, checksumType, contentChecksum);
computeChecksum->deleteLater();
} else {
connect(computeChecksum, &ComputeChecksum::done, this, [this, item, fileToUpload] (const QByteArray &contentChecksumType, const QByteArray &contentChecksum) {
slotStartUpload(item, fileToUpload, contentChecksumType, contentChecksum);
});
connect(computeChecksum, &ComputeChecksum::done, computeChecksum, &QObject::deleteLater);

computeChecksum->start(fileToUpload._path);
computeChecksum->start(fileToUpload._path);
}
}

void BulkPropagatorJob::slotStartUpload(SyncFileItemPtr item,
Expand Down Expand Up @@ -333,8 +344,10 @@ void BulkPropagatorJob::slotStartUpload(SyncFileItemPtr item,
return;
}

fileToUpload._size = FileSystem::getSize(fullFilePath);
item->_size = FileSystem::getSize(originalFilePath);
if (!item->isSymLink()) {
fileToUpload._size = FileSystem::getSize(fullFilePath);
item->_size = FileSystem::getSize(originalFilePath);
}

// But skip the file if the mtime is too close to 'now'!
// That usually indicates a file that is still being changed
Expand Down

0 comments on commit 0e645eb

Please sign in to comment.