QFileSystemModel: report special files which are not symlinks

Since special files have file size == -1, they were always filtered
out by QFileSystemModel, even when passing QDir::System as filtering
option. Keep them instead.

The testcase is more convoluted than it should be because QFSM
is so broken that it returns valid indexes for invisible elements
in the model (such as filtered out elements).

Change-Id: I023a9813dbfeed7be99dded42c66b1191afdc17e
Task-number: QTBUG-20968
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Giuseppe D'Angelo 2015-12-10 20:29:24 +01:00
parent be9df4bc82
commit 3b093034b6
2 changed files with 44 additions and 4 deletions

View File

@ -1791,10 +1791,6 @@ void QFileSystemModelPrivate::_q_fileSystemChanged(const QString &path, const QV
node->fileName = fileName;
}
if (info.size() == -1 && !info.isSymLink()) {
removeNode(parentNode, fileName);
continue;
}
if (*node != info ) {
node->populate(info);
bypassFilters.remove(node);

View File

@ -124,6 +124,7 @@ private slots:
void permissions();
void doNotUnwatchOnFailedRmdir();
void specialFiles();
protected:
bool createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount = 0, const QStringList &intial_dirs = QStringList());
@ -1077,6 +1078,49 @@ void tst_QFileSystemModel::doNotUnwatchOnFailedRmdir()
QTRY_COMPARE(model.rowCount(rootIndex), 2);
}
static QSet<QString> fileListUnderIndex(const QFileSystemModel *model, const QModelIndex &parent)
{
QSet<QString> fileNames;
const int rowCount = model->rowCount(parent);
for (int i = 0; i < rowCount; ++i)
fileNames.insert(model->index(i, 0, parent).data(QFileSystemModel::FileNameRole).toString());
return fileNames;
}
void tst_QFileSystemModel::specialFiles()
{
QFileSystemModel model;
model.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
// Can't simply verify if the model returns a valid model index for a special file
// as it will always return a valid index for existing files,
// even if the file is not visible with the given filter.
#if defined(Q_OS_UNIX)
const QModelIndex rootIndex = model.setRootPath(QStringLiteral("/dev/"));
const QString testFileName = QStringLiteral("null");
#elif defined(Q_OS_WIN)
const QModelIndex rootIndex = model.setRootPath(flatDirTestPath);
const QString testFileName = QStringLiteral("linkSource.lnk");
QFile file(flatDirTestPath + QLatin1String("/linkTarget.txt"));
QVERIFY(file.open(QIODevice::WriteOnly));
file.close();
QVERIFY(file.link(flatDirTestPath + '/' + testFileName));
#else
QSKIP("Not implemented");
QModelIndex rootIndex;
QString testFileName;
#endif
QTRY_VERIFY(fileListUnderIndex(&model, rootIndex).contains(testFileName));
model.setFilter(QDir::AllEntries | QDir::Hidden);
QTRY_VERIFY(!fileListUnderIndex(&model, rootIndex).contains(testFileName));
}
QTEST_MAIN(tst_QFileSystemModel)
#include "tst_qfilesystemmodel.moc"