Skip to content

Commit

Permalink
when deleting a remote locked file, provide needed lock headers
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu Gallien <[email protected]>
  • Loading branch information
mgallien authored and backportbot[bot] committed Mar 3, 2025
1 parent 2af9dd7 commit 2c58577
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/libsync/basepropagateremotedeleteencrypted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void BasePropagateRemoteDeleteEncrypted::deleteRemoteItem(const QString &filenam
{
qCInfo(ABSTRACT_PROPAGATE_REMOVE_ENCRYPTED) << "Deleting nested encrypted item" << filename;

const auto deleteJob = new DeleteJob(_propagator->account(), _propagator->fullRemotePath(filename), this);
const auto deleteJob = new DeleteJob(_propagator->account(), _propagator->fullRemotePath(filename), {}, this);
if (_encryptedFolderMetadataHandler && _encryptedFolderMetadataHandler->folderMetadata()
&& _encryptedFolderMetadataHandler->folderMetadata()->isValid()) {
deleteJob->setFolderToken(_encryptedFolderMetadataHandler->folderToken());
Expand Down
10 changes: 8 additions & 2 deletions src/libsync/deletejob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ namespace OCC {

Q_LOGGING_CATEGORY(lcDeleteJob, "nextcloud.sync.networkjob.delete", QtInfoMsg)

DeleteJob::DeleteJob(AccountPtr account, const QString &path, QObject *parent)
DeleteJob::DeleteJob(AccountPtr account, const QString &path, const QMap<QByteArray, QByteArray> &headers, QObject *parent)
: SimpleFileJob(account, path, parent)
, _headers(headers)
{
}

DeleteJob::DeleteJob(AccountPtr account, const QUrl &url, QObject *parent)
DeleteJob::DeleteJob(AccountPtr account, const QUrl &url, const QMap<QByteArray, QByteArray> &headers, QObject *parent)
: SimpleFileJob(account, QString(), parent)
, _headers(headers)
, _url(url)
{
}
Expand All @@ -38,6 +40,10 @@ void DeleteJob::start()
req.setRawHeader("e2e-token", _folderToken);
}

for (auto oneHeaderIt = _headers.begin(); oneHeaderIt != _headers.end(); ++oneHeaderIt) {
req.setRawHeader(oneHeaderIt.key(), oneHeaderIt.value());
}

if (_url.isValid()) {
startRequest("DELETE", _url, req);
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/libsync/deletejob.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ class DeleteJob : public SimpleFileJob
{
Q_OBJECT
public:
explicit DeleteJob(AccountPtr account, const QString &path, QObject *parent = nullptr);
explicit DeleteJob(AccountPtr account, const QUrl &url, QObject *parent = nullptr);
explicit DeleteJob(AccountPtr account, const QString &path, const QMap<QByteArray, QByteArray> &headers = {}, QObject *parent = nullptr);
explicit DeleteJob(AccountPtr account, const QUrl &url, const QMap<QByteArray, QByteArray> &headers = {}, QObject *parent = nullptr);

void start() override;

[[nodiscard]] QByteArray folderToken() const;
void setFolderToken(const QByteArray &folderToken);

private:
QMap<QByteArray, QByteArray> _headers = {};
QUrl _url; // Only used if the constructor taking a url is taken.
QByteArray _folderToken;
};
Expand Down
6 changes: 5 additions & 1 deletion src/libsync/propagateremotedelete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ void PropagateRemoteDelete::createDeleteJob(const QString &filename)

qCInfo(lcPropagateRemoteDelete) << "Deleting file, local" << _item->_file << "remote" << remoteFilename;

_job = new DeleteJob(propagator()->account(), propagator()->fullRemotePath(remoteFilename), this);
auto headers = QMap<QByteArray, QByteArray>{};
if (_item->_locked == SyncFileItem::LockStatus::LockedItem) {
headers[QByteArrayLiteral("If")] = (QLatin1String("<") + propagator()->account()->davUrl().toString() + _item->_file + "> (<opaquelocktoken:" + _item->_lockToken.toUtf8() + ">)").toUtf8();
}
_job = new DeleteJob(propagator()->account(), propagator()->fullRemotePath(remoteFilename), headers, this);
connect(_job.data(), &DeleteJob::finishedSignal, this, &PropagateRemoteDelete::slotDeleteJobFinished);
propagator()->_activeJobList.append(this);
_job->start();
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/propagateremotedeleteencryptedrootfolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void PropagateRemoteDeleteEncryptedRootFolder::deleteNestedRemoteItem(const QStr
{
qCInfo(PROPAGATE_REMOVE_ENCRYPTED_ROOTFOLDER) << "Deleting nested encrypted remote item" << filename;

auto deleteJob = new DeleteJob(_propagator->account(), _propagator->fullRemotePath(filename), this);
auto deleteJob = new DeleteJob(_propagator->account(), _propagator->fullRemotePath(filename), {}, this);
deleteJob->setFolderToken(folderToken());
deleteJob->setProperty(encryptedFileNamePropertyKey, filename);

Expand Down
5 changes: 3 additions & 2 deletions src/libsync/propagateremotemkdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ void PropagateRemoteMkdir::start()
}

_job = new DeleteJob(propagator()->account(),
propagator()->fullRemotePath(_item->_file),
this);
propagator()->fullRemotePath(_item->_file),
{},
this);
connect(qobject_cast<DeleteJob *>(_job), &DeleteJob::finishedSignal, this, &PropagateRemoteMkdir::slotMkdir);
_job->start();
}
Expand Down
5 changes: 3 additions & 2 deletions src/libsync/propagateupload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,9 @@ void PropagateUploadFileCommon::startUploadFile() {

qDebug() << "Deleting the current";
auto job = new DeleteJob(propagator()->account(),
propagator()->fullRemotePath(_fileToUpload._file),
this);
propagator()->fullRemotePath(_fileToUpload._file),
{},
this);
_jobs.append(job);
connect(job, &DeleteJob::finishedSignal, this, &PropagateUploadFileCommon::slotComputeContentChecksum);
connect(job, &QObject::destroyed, this, &PropagateUploadFileCommon::slotJobDestroyed);
Expand Down
6 changes: 3 additions & 3 deletions src/libsync/propagateuploadng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ void PropagateUploadFileNG::doStartUpload()
// The upload info is stale. remove the stale chunks on the server
_transferId = progressInfo._transferid;
// Fire and forget. Any error will be ignored.
(new DeleteJob(propagator()->account(), chunkUploadFolderUrl(), this))->start();
(new DeleteJob(propagator()->account(), chunkUploadFolderUrl(), {}, this))->start();
// startNewUpload will reset the _transferId and the UploadInfo in the db.
}

Expand Down Expand Up @@ -168,7 +168,7 @@ void PropagateUploadFileNG::slotPropfindFinished()

// Wipe the old chunking data.
// Fire and forget. Any error will be ignored.
(new DeleteJob(propagator()->account(), chunkUploadFolderUrl(), this))->start();
(new DeleteJob(propagator()->account(), chunkUploadFolderUrl(), {}, this))->start();

propagator()->_activeJobList.append(this);
startNewUpload();
Expand All @@ -186,7 +186,7 @@ void PropagateUploadFileNG::slotPropfindFinished()
// we should remove the later chunks. Otherwise when we do dynamic chunk sizing, we may end up
// with corruptions if there are too many chunks, or if we abort and there are still stale chunks.
for (const auto &serverChunk : std::as_const(_serverChunks)) {
auto job = new DeleteJob(propagator()->account(), Utility::concatUrlPath(chunkUploadFolderUrl(), serverChunk.originalName), this);
auto job = new DeleteJob(propagator()->account(), Utility::concatUrlPath(chunkUploadFolderUrl(), serverChunk.originalName), {}, this);
QObject::connect(job, &DeleteJob::finishedSignal, this, &PropagateUploadFileNG::slotDeleteJobFinished);
_jobs.append(job);
job->start();
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void SyncEngine::deleteStaleUploadInfos(const SyncFileItemVector &syncItems)
if (!transferId)
continue; // Was not a chunked upload
QUrl url = Utility::concatUrlPath(account()->url(), QLatin1String("remote.php/dav/uploads/") + account()->davUser() + QLatin1Char('/') + QString::number(transferId));
(new DeleteJob(account(), url, this))->start();
(new DeleteJob(account(), url, {}, this))->start();
}
}
}
Expand Down

0 comments on commit 2c58577

Please sign in to comment.