Skip to content

Commit

Permalink
Merge pull request #6141 from nextcloud/backport/6133/stable-3.10
Browse files Browse the repository at this point in the history
[stable-3.10] Fix chunk v2 destination header
  • Loading branch information
mgallien authored Oct 16, 2023
2 parents f662b0e + 2b96501 commit a21e89d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/common/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/libsync/propagateupload.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 11 additions & 4 deletions src/libsync/propagateuploadng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -268,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,
Expand Down Expand Up @@ -360,11 +369,9 @@ void PropagateUploadFileNG::startNextChunk()
return;
}

auto headers = PropagateUploadFileCommon::headers();
QMap<QByteArray, QByteArray> headers;
headers["OC-Chunk-Offset"] = QByteArray::number(_sent);

const auto destination = QDir::cleanPath(propagator()->account()->davUrl().path() + propagator()->fullRemotePath(_fileToUpload._file));
headers["Destination"] = destination.toUtf8();
headers["Destination"] = destinationHeader();

_sent += _currentChunkSize;
const auto url = chunkUrl(_currentChunk);
Expand Down

0 comments on commit a21e89d

Please sign in to comment.