From: David Edmundson Date: Thu, 7 Dec 2023 11:14:45 +0000 (+0100) Subject: Do not cache indexes across async tasks X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/30691235c5acc4c5b30ffc8820d2ef7c55fc632e Do not cache indexes across async tasks Capturing an index is unsafe as it could be out of date when this is processed. The user could have changed directory inserted a file or changed sorting order. --- diff --git a/src/kitemviews/kfileitemmodelrolesupdater.cpp b/src/kitemviews/kfileitemmodelrolesupdater.cpp index 06500b45d..bcd172d02 100644 --- a/src/kitemviews/kfileitemmodelrolesupdater.cpp +++ b/src/kitemviews/kfileitemmodelrolesupdater.cpp @@ -1315,7 +1315,11 @@ void KFileItemModelRolesUpdater::startDirectorySizeCounting(const KFileItem &ite connect(m_model, &KFileItemModel::itemsChanged, this, &KFileItemModelRolesUpdater::slotItemsChanged); auto listJob = KIO::listDir(url, KIO::HideProgressInfo); - QObject::connect(listJob, &KIO::ListJob::entries, this, [this, index](const KJob * /*job*/, const KIO::UDSEntryList &list) { + QObject::connect(listJob, &KIO::ListJob::entries, this, [this, item](const KJob * /*job*/, const KIO::UDSEntryList &list) { + int index = m_model->index(item); + if (index < 0) { + return; + } auto data = m_model->data(index); int origCount = data.value("count").toInt(); int entryCount = origCount;