File patch-r889593.diff of Package kdelibs4

Subject: Fix item not disappearing when renaming it to ".f
From: wstephenson@suse.de
Bug: kde#164974
Patch-upstream: 889593
--- kio/kio/kdirlister.cpp	(revision 889592)
+++ kio/kio/kdirlister.cpp	(revision 889593)
@@ -1526,7 +1526,7 @@ void KDirListerCache::slotUpdateResult(
                 foreach ( KDirLister *kdl, listers )
                     kdl->d->aboutToRefreshItem( *tmp );
 
-                // kDebug(7004) << "slotUpdateResult: file changed: " << tmp->name();
+                //kDebug(7004) << "file changed:" << tmp->name();
 
                 const KFileItem oldItem = *tmp;
                 *tmp = item;
@@ -1537,7 +1537,7 @@ void KDirListerCache::slotUpdateResult(
         }
         else // this is a new file
         {
-            // kDebug(7004) << "slotUpdateResult: new file: " << name;
+            //kDebug(7004) << "new file:" << name;
 
             KFileItem pitem(item);
             pitem.mark();
@@ -1609,7 +1609,7 @@ void KDirListerCache::deleteUnmarkedItem
     while (kit.hasNext()) {
         const KFileItem item = kit.next();
         if (!item.isMarked()) {
-            //kDebug() << item->name();
+            //kDebug() << "deleted:" << item.name();
             deletedItems.append(item);
             kit.remove();
         }
@@ -2250,8 +2250,9 @@ void KDirLister::Private::addRefreshItem
 
     // notify the user that the mimetype of a file changed that doesn't match
     // a filter or does match an exclude filter
-    Q_ASSERT( !item.isNull() );
-    lstRemoveItems->append( item );
+    // This also happens when renaming foo to .foo and dot files are hidden (#174721)
+    Q_ASSERT(!oldItem.isNull());
+    lstRemoveItems->append(oldItem);
   }
 }
 
--- kio/tests/kdirmodeltest.cpp	(revision 889592)
+++ kio/tests/kdirmodeltest.cpp	(revision 889593)
@@ -107,6 +107,13 @@ void KDirModelTest::fillModel(bool reloa
     disconnect(dirLister, SIGNAL(completed()), this, SLOT(slotListingCompleted()));
 }
 
+// Called after test function
+void KDirModelTest::cleanup()
+{
+    disconnect(&m_dirModel, 0, &m_eventLoop, 0);
+    disconnect(m_dirModel.dirLister(), 0, this, 0);
+}
+
 void KDirModelTest::collectKnownIndexes()
 {
     m_dirIndex = QModelIndex();
@@ -363,10 +370,8 @@ void KDirModelTest::testModifyFile()
 
 void KDirModelTest::testRenameFile()
 {
-    const QString file = m_tempDir->name() + "toplevelfile_2";
-    const KUrl url(file);
-    const QString newFile = m_tempDir->name() + "toplevelfile_2_renamed";
-    const KUrl newUrl(newFile);
+    const KUrl url(m_tempDir->name() + "toplevelfile_2");
+    const KUrl newUrl(m_tempDir->name() + "toplevelfile_2_renamed");
 
     QSignalSpy spyDataChanged(&m_dirModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)));
     connect( &m_dirModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
@@ -605,7 +610,6 @@ void KDirModelTest::testUrlWithHost() //
     enterLoop();
 
     QCOMPARE(dirLister->url().url(), QString("fonts:/System"));
-    disconnect(dirLister, SIGNAL(completed()), this, SLOT(slotListingCompleted()));
 }
 
 void KDirModelTest::testZipFile() // # 171721
@@ -696,4 +700,56 @@ void KDirModelTest::testDeleteFiles()
 
     const int topLevelRowCount = m_dirModel.rowCount();
     QCOMPARE(topLevelRowCount, oldTopLevelRowCount - 3); // three less than before
+
+    recreateTestData();
+    fillModel(false);
 }
+
+// A renaming that looks more like a deletion to the model
+void KDirModelTest::testRenameFileToHidden() // #174721
+{
+    const KUrl url(m_tempDir->name() + "toplevelfile_2");
+    const KUrl newUrl(m_tempDir->name() + ".toplevelfile_2");
+
+    QSignalSpy spyDataChanged(&m_dirModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)));
+    QSignalSpy spyRowsRemoved(&m_dirModel, SIGNAL(rowsRemoved(QModelIndex,int,int)));
+    QSignalSpy spyRowsInserted(&m_dirModel, SIGNAL(rowsInserted(QModelIndex,int,int)));
+    connect( &m_dirModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
+             &m_eventLoop, SLOT(quit()) );
+
+    KIO::SimpleJob* job = KIO::rename(url, newUrl, KIO::HideProgressInfo);
+    bool ok = job->exec();
+    QVERIFY(ok);
+
+    // Wait for the DBUS signal from KDirNotify, it's the one the triggers KDirLister
+    enterLoop();
+
+    // If we come here, then rowsRemoved() was emitted - all good.
+    QCOMPARE(spyDataChanged.count(), 0);
+    QCOMPARE(spyRowsRemoved.count(), 1);
+    QCOMPARE(spyRowsInserted.count(), 0);
+    COMPARE_INDEXES(spyRowsRemoved[0][0].value<QModelIndex>(), QModelIndex()); // parent is invalid
+    const int row = spyRowsRemoved[0][1].toInt();
+    QCOMPARE(row, m_secondFileIndex.row()); // only compare row
+
+    disconnect(&m_dirModel, SIGNAL(rowsRemoved(QModelIndex,int,int)),
+               &m_eventLoop, SLOT(quit()));
+    spyRowsRemoved.clear();
+
+    // Put things back to normal, should make the file reappear
+    connect(&m_dirModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
+            &m_eventLoop, SLOT(quit()));
+    job = KIO::rename(newUrl, url, KIO::HideProgressInfo);
+    ok = job->exec();
+    QVERIFY(ok);
+    // Wait for the DBUS signal from KDirNotify, it's the one the triggers KDirLister
+    enterLoop();
+    QCOMPARE(spyDataChanged.count(), 0);
+    QCOMPARE(spyRowsRemoved.count(), 0);
+    QCOMPARE(spyRowsInserted.count(), 1);
+    int newRow = spyRowsInserted[0][1].toInt();
+    m_secondFileIndex = m_dirModel.index(newRow, 0);
+    QVERIFY(m_secondFileIndex.isValid());
+    QCOMPARE(m_dirModel.itemForIndex( m_secondFileIndex ).url().url(), url.url());
+}
+
--- kio/tests/kdirmodeltest.h	(revision 889592)
+++ kio/tests/kdirmodeltest.h	(revision 889593)
@@ -31,6 +31,7 @@ class KDirModelTest : public QObject
 private Q_SLOTS:
     void initTestCase();
     void cleanupTestCase();
+    void cleanup();
     void testRowCount();
     void testIndex();
     void testNames();
@@ -52,6 +53,7 @@ private Q_SLOTS:
     // These two must be done last
     void testDeleteFile();
     void testDeleteFiles();
+    void testRenameFileToHidden();
 
 protected Q_SLOTS: // 'more private than private slots' - i.e. not seen by qtestlib
     void slotListingCompleted();
Index: kio/kio/kdirlister.cpp
===================================================================
Index: kio/tests/kdirmodeltest.cpp
===================================================================
Index: kio/tests/kdirmodeltest.h
===================================================================
openSUSE Build Service is sponsored by