File KCoreDirLister-fix-crash-when-creating-new-folders-from-kfilewidget.patch of Package kio

From f539b17ceec2a8c7a453228b7db62a7919b849be Mon Sep 17 00:00:00 2001
From: Ahmad Samir <a.samirh78@gmail.com>
Date: Sun, 15 Sep 2019 12:18:26 +0200
Subject: KCoreDirLister: fix crash when creating new folders from kfilewidget

Summary:
When creating multiple nested new folders, one at a time, in the "save as"
dialog, where folders are created and entered, a dirlister would hit an
assert (in DirItem::reinsert()), because one of the created folders would
eventually get inserted in pendingUpdates.

Add a unit test in kfilewidgettest.

BUG: 401916
FIXED-IN: 5.63.0

Test Plan:
- Open a file in e.g. okular, then "save as"
- Create a new folder from the dialog, then another ... etc, usually 2-3
  new folders would hit the assert (keep going, the number varies apparently)
  and the app would crash
- Apply the patch then try again, it shouldn't crash

Reviewers: #frameworks, ahmadsamir

Subscribers: dhaumann, kde-frameworks-devel

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D23875
---
 autotests/kfilewidgettest.cpp | 23 +++++++++++++++++++++++
 src/core/kcoredirlister.cpp   |  6 ------
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/autotests/kfilewidgettest.cpp b/autotests/kfilewidgettest.cpp
index c608a72..c0e4581 100644
--- a/autotests/kfilewidgettest.cpp
+++ b/autotests/kfilewidgettest.cpp
@@ -22,6 +22,7 @@
 #include "kfilewidget.h"
 
 #include <QLabel>
+#include <QTemporaryDir>
 #include <QTest>
 #include <QStandardPaths>
 
@@ -245,6 +246,28 @@ private Q_SLOTS:
         QVERIFY(u.isValid());
         QCOMPARE(u, expectedUrl);
     }
+
+    void testCreateNestedNewFolders()
+    {
+        // when creating multiple nested new folders in the "save as" dialog, where folders are
+        //created and entered, kdirlister would hit an assert (in reinsert()), bug 408801
+        QTemporaryDir tempDir;
+        QVERIFY(tempDir.isValid());
+        const QString dir = tempDir.path();
+        const QUrl url = QUrl::fromLocalFile(dir);
+        KFileWidget fw(url);
+        fw.setOperationMode(KFileWidget::Saving);
+        fw.setMode(KFile::File);
+
+        // create the nested folders
+        for (int i = 1; i < 6; ++i) {
+            fw.dirOperator()->mkdir(QStringLiteral("folder%1").arg(i), true);
+            // simulate the time the user will take to type the new folder name
+            QTest::qWait(1000);
+        }
+
+        QVERIFY(QFile::exists(dir + QStringLiteral("/folder1/folder2/folder3/folder4/folder5")));
+    }
 };
 
 QTEST_MAIN(KFileWidgetTest)
diff --git a/src/core/kcoredirlister.cpp b/src/core/kcoredirlister.cpp
index 4dbe0f9..0fcbeb4 100644
--- a/src/core/kcoredirlister.cpp
+++ b/src/core/kcoredirlister.cpp
@@ -644,12 +644,6 @@ void KCoreDirListerCache::updateDirectory(const QUrl &_dir)
 
     const QUrl dir = _dir.adjusted(QUrl::StripTrailingSlash);
     if (!checkUpdate(dir)) {
-        if (dir.isLocalFile() && !(findByUrl(nullptr, dir).isNull())) {
-            pendingUpdates.insert(dir.toLocalFile());
-            if (!pendingUpdateTimer.isActive()) {
-                pendingUpdateTimer.start(500);
-            }
-        }
         return;
     }
 
-- 
cgit v1.1

openSUSE Build Service is sponsored by