From 8d3ac10d0bc5bc0c9d83f91e015fbc73efe86549 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 11 Oct 2023 15:36:09 +0800 Subject: [PATCH 1/4] Add utility method to remove leading slashes from paths Signed-off-by: Claudio Cambra --- src/common/utility.cpp | 7 +++++++ src/common/utility.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/common/utility.cpp b/src/common/utility.cpp index 61f2489e4255b..607bb0414ec7c 100644 --- a/src/common/utility.cpp +++ b/src/common/utility.cpp @@ -729,4 +729,11 @@ QString Utility::trailingSlashPath(const QString &path) return path.endsWith(slash) ? path : QString(path + slash); } +QString Utility::noLeadingSlashPath(const QString &path) +{ + static const auto slash = QLatin1Char('/'); + return path.startsWith(slash) ? path.mid(1) : path; +} + + } // namespace OCC diff --git a/src/common/utility.h b/src/common/utility.h index b554a196be189..e19f0da6ae1ee 100644 --- a/src/common/utility.h +++ b/src/common/utility.h @@ -256,6 +256,7 @@ namespace Utility { OCSYNC_EXPORT void registerUriHandlerForLocalEditing(); OCSYNC_EXPORT QString trailingSlashPath(const QString &path); + OCSYNC_EXPORT QString noLeadingSlashPath(const QString &path); #ifdef Q_OS_WIN OCSYNC_EXPORT bool registryKeyExists(HKEY hRootKey, const QString &subKey); From 55d61f54fbe9120f64a4383150ca5ee3055868dc Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 11 Oct 2023 15:36:32 +0800 Subject: [PATCH 2/4] Provide full url for chunked upload destination header Signed-off-by: Claudio Cambra --- src/libsync/propagateuploadng.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libsync/propagateuploadng.cpp b/src/libsync/propagateuploadng.cpp index 2330c5c647d72..437fd7adce875 100644 --- a/src/libsync/propagateuploadng.cpp +++ b/src/libsync/propagateuploadng.cpp @@ -360,10 +360,12 @@ void PropagateUploadFileNG::startNextChunk() return; } - auto headers = PropagateUploadFileCommon::headers(); + QMap headers; headers["OC-Chunk-Offset"] = QByteArray::number(_sent); - const auto destination = QDir::cleanPath(propagator()->account()->davUrl().path() + propagator()->fullRemotePath(_fileToUpload._file)); + const auto davUrl = Utility::trailingSlashPath(propagator()->account()->davUrl().toString()); + const auto remotePath = Utility::noLeadingSlashPath(propagator()->fullRemotePath(_fileToUpload._file)); + const auto destination = QString(davUrl + remotePath); headers["Destination"] = destination.toUtf8(); _sent += _currentChunkSize; From 7af9062923bf3fd2692c8ef37819f6498fdb862f Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 11 Oct 2023 16:19:30 +0800 Subject: [PATCH 3/4] Move destination header build to own method Signed-off-by: Claudio Cambra --- src/libsync/propagateupload.h | 1 + src/libsync/propagateuploadng.cpp | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/libsync/propagateupload.h b/src/libsync/propagateupload.h index e12e4500a5efc..33db43f297755 100644 --- a/src/libsync/propagateupload.h +++ b/src/libsync/propagateupload.h @@ -410,6 +410,7 @@ private slots: [[nodiscard]] QUrl chunkUploadFolderUrl() const; [[nodiscard]] QUrl chunkUrl(const int chunk) const; + [[nodiscard]] QByteArray destinationHeader() const; void startNewUpload(); void startNextChunk(); diff --git a/src/libsync/propagateuploadng.cpp b/src/libsync/propagateuploadng.cpp index 437fd7adce875..e477cb8306010 100644 --- a/src/libsync/propagateuploadng.cpp +++ b/src/libsync/propagateuploadng.cpp @@ -85,6 +85,14 @@ QUrl PropagateUploadFileNG::chunkUrl(const int chunk) const */ +QByteArray PropagateUploadFileNG::destinationHeader() const +{ + const auto davUrl = Utility::trailingSlashPath(propagator()->account()->davUrl().toString()); + const auto remotePath = Utility::noLeadingSlashPath(propagator()->fullRemotePath(_fileToUpload._file)); + const auto destination = QString(davUrl + remotePath); + return destination.toUtf8(); +} + void PropagateUploadFileNG::doStartUpload() { propagator()->_activeJobList.append(this); @@ -362,11 +370,7 @@ void PropagateUploadFileNG::startNextChunk() QMap headers; headers["OC-Chunk-Offset"] = QByteArray::number(_sent); - - const auto davUrl = Utility::trailingSlashPath(propagator()->account()->davUrl().toString()); - const auto remotePath = Utility::noLeadingSlashPath(propagator()->fullRemotePath(_fileToUpload._file)); - const auto destination = QString(davUrl + remotePath); - headers["Destination"] = destination.toUtf8(); + headers["Destination"] = destinationHeader(); _sent += _currentChunkSize; const auto url = chunkUrl(_currentChunk); From 2b965011838b5bf4269511a54aac2dee04cd6d87 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 11 Oct 2023 16:28:38 +0800 Subject: [PATCH 4/4] Also add destination header to initial chunk folder MKCOL Signed-off-by: Claudio Cambra --- src/libsync/propagateuploadng.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libsync/propagateuploadng.cpp b/src/libsync/propagateuploadng.cpp index e477cb8306010..4642d857b6929 100644 --- a/src/libsync/propagateuploadng.cpp +++ b/src/libsync/propagateuploadng.cpp @@ -276,6 +276,7 @@ void PropagateUploadFileNG::startNewUpload() // But we should send the temporary (or something) one. headers["OC-Total-Length"] = QByteArray::number(_fileToUpload._size); + headers["Destination"] = destinationHeader(); const auto job = new MkColJob(propagator()->account(), chunkUploadFolderUrl(), headers, this); connect(job, &MkColJob::finishedWithError,