Skip to content

Commit

Permalink
Include mtime in tus Upload-Metadata (#10958)
Browse files Browse the repository at this point in the history
Fixes: #10950
(cherry picked from commit 66e29f0)
  • Loading branch information
TheOneRing committed Aug 4, 2023
1 parent adc89fe commit f5090a5
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/libsync/propagateuploadtus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,19 @@ UploadDevice *PropagateUploadFileTUS::prepareDevice(const quint64 &chunkSize)
SimpleNetworkJob *PropagateUploadFileTUS::makeCreationWithUploadJob(QNetworkRequest *request, UploadDevice *device)
{
Q_ASSERT(propagator()->account()->capabilities().tusSupport().extensions.contains(QStringLiteral("creation-with-upload")));
// in difference to the old protocol the algrithm and the value are space seperated

const auto checksumHeader = ChecksumHeader::parseChecksumHeader(_transmissionChecksumHeader);
const QByteArray checkSum = QByteArray(CheckSums::toQString(checksumHeader.type()).toUtf8() + ' ' + checksumHeader.checksum()).toBase64();
const QByteArray base64Path = propagator()->fullRemotePath(_item->_file).toUtf8().toBase64();
qCDebug(lcPropagateUploadTUS) << "FullPath:" << propagator()->fullRemotePath(_item->_file) << "Base64:" << base64Path;
request->setRawHeader(QByteArrayLiteral("Upload-Metadata"), "filename " + base64Path + ",checksum " + checkSum);

QByteArrayList encodedMetaData;
auto addMetaData = [&encodedMetaData](const QByteArray &key, const QByteArray &value) { encodedMetaData << key + ' ' + value.toBase64(); };
addMetaData(QByteArrayLiteral("filename"), propagator()->fullRemotePath(_item->_file).toUtf8());
// in difference to the old protocol the algrithm and the value are space seperated
addMetaData(QByteArrayLiteral("checksum"), CheckSums::toQString(checksumHeader.type()).toUtf8() + ' ' + checksumHeader.checksum());
addMetaData(QByteArrayLiteral("mtime"), QByteArray::number(_item->_modtime));

request->setRawHeader(QByteArrayLiteral("Upload-Metadata"), encodedMetaData.join(','));
request->setRawHeader(QByteArrayLiteral("Upload-Length"), QByteArray::number(_item->_size));
auto job = new SimpleNetworkJob(propagator()->account(), propagator()->webDavUrl(), {}, "POST", device, *request, this);
return job;
return new SimpleNetworkJob(propagator()->account(), propagator()->webDavUrl(), {}, "POST", device, *request, this);
}

QNetworkRequest PropagateUploadFileTUS::prepareRequest(const quint64 &chunkSize)
Expand Down

0 comments on commit f5090a5

Please sign in to comment.