From b6e03e05f4b63dc86c763f73ec863137ea59d2f0 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Fri, 7 Jan 2022 17:05:30 +0000 Subject: Fix issue where newly inserted items end up in the wrong directory If we have directory "a" and "a/b" and expand both, then collapse "a" we tell KDirWatcher to stop watching both these directories. However, KDirWatcher keeps them in the listersCurrentlyHolding list as well as the listersCurrentlyListing list and will still notify of changes. If a new file appears in "a/b/" we will still get change notifications. When dolphin processes these changes we cannot find the relevant parent node. It then gets confused and inserts the item into the root directory from the POV of the model notifications. When we then open the relevant folder the model knows a node with that URL exists and fails to add it correctly. This can also be reproduced by continually downloading files into a subdirectory tree and rapidly expanding and collapsing folders a few levels deep. --- src/kitemviews/kfileitemmodel.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/kitemviews/kfileitemmodel.cpp') diff --git a/src/kitemviews/kfileitemmodel.cpp b/src/kitemviews/kfileitemmodel.cpp index 23afb087a..6391d7d3f 100644 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -575,6 +576,9 @@ bool KFileItemModel::setExpanded(int index, bool expanded) m_expandedDirs.remove(targetUrl); m_dirLister->stop(url); +#if KIO_VERSION >= QT_VERSION_CHECK(5, 92, 0) + m_dirLister->forgetDirs(url); +#endif const int parentLevel = expandedParentsCount(index); const int itemCount = m_itemData.count(); @@ -590,6 +594,9 @@ bool KFileItemModel::setExpanded(int index, bool expanded) const QUrl url = itemData->item.url(); m_expandedDirs.remove(targetUrl); m_dirLister->stop(url); // TODO: try to unit-test this, see https://bugs.kde.org/show_bug.cgi?id=332102#c11 +#if KIO_VERSION >= QT_VERSION_CHECK(5, 92, 0) + m_dirLister->forgetDirs(url); +#endif expandedChildren.append(targetUrl); } ++childIndex; -- cgit v1.3