Skip to content

Commit

Permalink
make use of the new x-nc-skip-trashbin header
Browse files Browse the repository at this point in the history
Signed-off-by: Jyrki Gadinger <[email protected]>
  • Loading branch information
nilsding authored and mgallien committed Mar 6, 2025
1 parent 06b9a82 commit e794446
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/libsync/basepropagateremotedeleteencrypted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,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);
deleteJob->setSkipTrashbin(true);
if (_encryptedFolderMetadataHandler && _encryptedFolderMetadataHandler->folderMetadata()
&& _encryptedFolderMetadataHandler->folderMetadata()->isValid()) {
deleteJob->setFolderToken(_encryptedFolderMetadataHandler->folderToken());
Expand Down
14 changes: 14 additions & 0 deletions src/libsync/deletejob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ void DeleteJob::start()
req.setRawHeader(oneHeaderIt.key(), oneHeaderIt.value());
}

if (_skipTrashbin) {
req.setRawHeader("X-NC-Skip-Trashbin", "true");
}

if (_url.isValid()) {
startRequest("DELETE", _url, req);
} else {
Expand All @@ -61,4 +65,14 @@ void DeleteJob::setFolderToken(const QByteArray &folderToken)
_folderToken = folderToken;
}

bool DeleteJob::skipTrashbin() const
{
return _skipTrashbin;
}

void DeleteJob::setSkipTrashbin(bool skipTrashbin)
{
_skipTrashbin = skipTrashbin;
}

} // namespace OCC
4 changes: 4 additions & 0 deletions src/libsync/deletejob.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ class DeleteJob : public SimpleFileJob
[[nodiscard]] QByteArray folderToken() const;
void setFolderToken(const QByteArray &folderToken);

[[nodiscard]] bool skipTrashbin() const;
void setSkipTrashbin(bool skipTrashbin);

private:
QMap<QByteArray, QByteArray> _headers = {};
QUrl _url; // Only used if the constructor taking a url is taken.
QByteArray _folderToken;
bool _skipTrashbin = false;
};
}
6 changes: 6 additions & 0 deletions src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,11 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
const bool isOnlineOnlyItem = isCfApiVfsMode && (localEntry.isDirectory || _discoveryData->_syncOptions._vfs->isDehydratedPlaceholder(_discoveryData->_localDir + path._local));
const auto isE2eeMoveOnlineOnlyItemWithCfApi = isE2eeMove && isOnlineOnlyItem;

if (isE2eeMove) {
qCInfo(lcDisco) << "requesting permanent deletion for" << originalPath;
_discoveryData->_permanentDeletionRequests.insert(originalPath);
}

if (isE2eeMoveOnlineOnlyItemWithCfApi) {
item->_instruction = CSYNC_INSTRUCTION_NEW;
item->_direction = SyncFileItem::Down;
Expand Down Expand Up @@ -1784,6 +1789,7 @@ void ProcessDirectoryJob::processFileFinalize(
job->setInsideEncryptedTree(isInsideEncryptedTree() || item->isEncrypted());
if (removed) {
job->setParent(_discoveryData);
_discoveryData->_deletedItem[path._original] = item;
_discoveryData->enqueueDirectoryToDelete(path._original, job);
} else {
connect(job, &ProcessDirectoryJob::finished, this, &ProcessDirectoryJob::subJobFinished);
Expand Down
23 changes: 23 additions & 0 deletions src/libsync/discoveryphase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,28 @@ void DiscoveryPhase::enqueueDirectoryToDelete(const QString &path, ProcessDirect
}
}

void DiscoveryPhase::markPermanentDeletionRequests()
{
// since we don't know in advance which files/directories need to be permanently deleted,
// we have to look through all of them at the end of the run
for (const auto &originalPath : _permanentDeletionRequests) {
const auto it = _deletedItem.find(originalPath);
if (it == _deletedItem.end()) {
qCWarning(lcDiscovery) << "didn't find an item for" << originalPath << "(yet)";
continue;
}

auto item = *it;
if (!(item->_instruction == CSYNC_INSTRUCTION_REMOVE || item->_direction == SyncFileItem::Up)) {
qCWarning(lcDiscovery) << "will not request permanent deletion for" << originalPath << "as the instruction is not CSYNC_INSTRUCTION_REMOVE, or the direction is not Up";
continue;
}

qCInfo(lcDiscovery) << "requested permanent server-side deletion for" << originalPath;
item->_wantsPermanentDeletion = true;
}
}

void DiscoveryPhase::startJob(ProcessDirectoryJob *job)

Check warning on line 250 in src/libsync/discoveryphase.cpp

View workflow job for this annotation

GitHub Actions / build

src/libsync/discoveryphase.cpp:250:22 [readability-convert-member-functions-to-static]

method 'startJob' can be made static
{
ENFORCE(!_currentRootJob);
Expand All @@ -242,6 +264,7 @@ void DiscoveryPhase::startJob(ProcessDirectoryJob *job)
auto nextJob = _queuedDeletedDirectories.take(_queuedDeletedDirectories.firstKey());
startJob(nextJob);
} else {
markPermanentDeletionRequests();
emit finished();
}
});
Expand Down
5 changes: 5 additions & 0 deletions src/libsync/discoveryphase.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ class DiscoveryPhase : public QObject

void enqueueDirectoryToDelete(const QString &path, ProcessDirectoryJob* const directoryJob);

/// contains files/folder names that are requested to be deleted permanently
QSet<QString> _permanentDeletionRequests;

void markPermanentDeletionRequests();

public:
// input
QString _localDir; // absolute path to the local directory. ends with '/'
Expand Down
3 changes: 2 additions & 1 deletion src/libsync/propagateremotedelete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ void PropagateRemoteDelete::createDeleteJob(const QString &filename)
}
}

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

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);
_job->setSkipTrashbin(_item->_wantsPermanentDeletion);
connect(_job.data(), &DeleteJob::finishedSignal, this, &PropagateRemoteDelete::slotDeleteJobFinished);
propagator()->_activeJobList.append(this);
_job->start();
Expand Down
1 change: 1 addition & 0 deletions src/libsync/propagateremotedeleteencryptedrootfolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ void PropagateRemoteDeleteEncryptedRootFolder::deleteNestedRemoteItem(const QStr
auto deleteJob = new DeleteJob(_propagator->account(), _propagator->fullRemotePath(filename), {}, this);
deleteJob->setFolderToken(folderToken());
deleteJob->setProperty(encryptedFileNamePropertyKey, filename);
deleteJob->setSkipTrashbin(true);

connect(deleteJob, &DeleteJob::finishedSignal, this, &PropagateRemoteDeleteEncryptedRootFolder::slotDeleteNestedRemoteItemFinished);

Expand Down
4 changes: 4 additions & 0 deletions src/libsync/syncfileitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ class OWNCLOUDSYNC_EXPORT SyncFileItem
bool isPermissionsInvalid = false;

QString _discoveryResult;

/// if true, requests the file to be permanently deleted instead of moved to the trashbin
/// only relevant for when `_instruction` is set to `CSYNC_INSTRUCTION_REMOVE`
bool _wantsPermanentDeletion = false;
};

inline bool operator<(const SyncFileItemPtr &item1, const SyncFileItemPtr &item2)
Expand Down

0 comments on commit e794446

Please sign in to comment.