]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Do not cache indexes across async tasks
authorDavid Edmundson <kde@davidedmundson.co.uk>
Thu, 7 Dec 2023 11:14:45 +0000 (12:14 +0100)
committerDavid Edmundson <kde@davidedmundson.co.uk>
Fri, 8 Dec 2023 09:50:24 +0000 (09:50 +0000)
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.

src/kitemviews/kfileitemmodelrolesupdater.cpp

index 06500b45dd168f9a2ddee88a5af07a3fe626f807..bcd172d026103f9786fe9ab4b1a82a2f435bff38 100644 (file)
@@ -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;