From: Olivier Goffart Date: Tue, 29 Nov 2016 16:17:06 +0000 (+0100) Subject: FolderStatusModel: Fix insert/remove items when there are labels X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~960 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=775a1c9ad8c3b635dce7eac3a641220500869677;p=nextcloud-desktop.git FolderStatusModel: Fix insert/remove items when there are labels Otherwise it might happen that the model is inconsistant and this can lead to crash in the worst case. (For example, if there was a "fetching" label, and we hide it because it was a 404. In this case, we would not call begin/endRemoveRows, so the view could still call the model with an index of row 0, that used to be for the label, but now correspond to the first element of _subs. And because _subs is empty, this could lead to crashes) --- diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index 1bd5fcc25..42b787d14 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -527,10 +527,8 @@ void FolderStatusModel::fetchMore(const QModelIndex& parent) if (!info || info->_fetched || info->_fetching) return; - - info->_hasError = false; + info->resetSubs(this, parent); info->_fetching = true; - info->_fetchingLabel = false; QString path = info->_folder->remotePath(); if (info->_path != QLatin1String("/")) { if (!path.endsWith(QLatin1Char('/'))) { @@ -698,17 +696,16 @@ void FolderStatusModel::slotLscolFinishedWithError(QNetworkReply* r) qDebug() << r->errorString(); parentInfo->_lastErrorString = r->errorString(); + parentInfo->resetSubs(this, idx); + if (r->error() == QNetworkReply::ContentNotFoundError) { parentInfo->_fetched = true; } else { - if (!parentInfo->hasLabel()) { - beginInsertRows(idx, 0, 0); - endInsertRows(); - } + Q_ASSERT(!parentInfo->hasLabel()); + beginInsertRows(idx, 0, 0); parentInfo->_hasError = true; + endInsertRows(); } - parentInfo->_fetching = false; - parentInfo->_fetchingLabel = false; } }