fix: ignore directory listing entry for the iterated directory

The `ignoreFirst` bool had a short lifetime, by the time the lambda slot
handling the `LsColJob::directoryListingIterated` signal was called the
reference to that bool would report a completely different value.  This
could result in the first entry of a directory listing to not be ignored
properly.

This commit changes the way the slot checks whether it's currently
iterating over the very same directory that was just requested by
comparing the request path with the path from the response.

Fixes #8915

Signed-off-by: Jyrki Gadinger <nilsding@nilsding.org>
This commit is contained in:
Jyrki Gadinger 2025-10-22 11:42:21 +02:00
parent 4417cf60d4
commit 438b0af64b

View File

@ -1213,11 +1213,14 @@ void Account::listRemoteFolder(QPromise<OCC::PlaceholderCreateInfo> *promise, co
promise->finish();
});
auto ignoreFirst = true;
QObject::connect(listFolderJob, &OCC::LsColJob::directoryListingIterated, this, [&ignoreFirst, promise, path, journalForFolder, this] (const QString &name, const QMap<QString, QString> &properties) {
if (ignoreFirst) {
QObject::connect(listFolderJob, &OCC::LsColJob::directoryListingIterated, this, [promise, path, journalForFolder, this](const QString &name, const QMap<QString, QString> &properties) {
// `name` is e.g. "/remote.php/dav/files/admin" or "/remote.php/dav/files/admin/SomeFolder"; whereas `path` is e.g. "" or "SomeFolder/"
// in case these two are equal we are currently iterating the entry for the current directory
const auto serverPath = name.mid(this->davPath().size());
const auto isRootCollection = serverPath.isEmpty() && path.isEmpty();
const auto isCurrentCollection = isRootCollection || serverPath == Utility::noTrailingSlashPath(path);
if (isCurrentCollection) {
qCDebug(lcAccount()) << "skip first item";
ignoreFirst = false;
return;
}