FolderStatusModel: fix assert in Qt when the list of subfolder is empty
authorOlivier Goffart <ogoffart@woboq.com>
Mon, 29 May 2017 11:00:43 +0000 (13:00 +0200)
committerOlivier Goffart <olivier@woboq.com>
Tue, 6 Jun 2017 12:49:03 +0000 (14:49 +0200)
Fix an assert that happens in beginInsertRows when opening a folder
and that folder is empty.
This can only be reproduced with a debug build of Qt.

src/gui/folderstatusmodel.cpp

index 037285b530645b1f901330eda2de58074eb8ba29..b0f83e9c8edc62ac3852afc876118fecda85d75b 100644 (file)
@@ -614,6 +614,8 @@ void FolderStatusModel::slotUpdateDirectories(const QStringList &list)
     if (!parentInfo) {
         return;
     }
+    ASSERT(parentInfo->_fetching); // we should only get a result if we were doing a fetch
+    ASSERT(parentInfo->_subs.isEmpty());
 
     if (parentInfo->hasLabel()) {
         beginRemoveRows(idx, 0, 0);
@@ -712,9 +714,11 @@ void FolderStatusModel::slotUpdateDirectories(const QStringList &list)
         newSubs.append(newInfo);
     }
 
-    beginInsertRows(idx, 0, newSubs.size() - 1);
-    parentInfo->_subs = std::move(newSubs);
-    endInsertRows();
+    if (!newSubs.isEmpty()) {
+        beginInsertRows(idx, 0, newSubs.size() - 1);
+        parentInfo->_subs = std::move(newSubs);
+        endInsertRows();
+    }
 
     for (auto it = undecidedIndexes.begin(); it != undecidedIndexes.end(); ++it) {
         suggestExpand(idx.child(*it, 0));