diff --git a/src/corelib/io/qfilesystemwatcher_win.cpp b/src/corelib/io/qfilesystemwatcher_win.cpp index 7586054c27e..a0b2b006d6e 100644 --- a/src/corelib/io/qfilesystemwatcher_win.cpp +++ b/src/corelib/io/qfilesystemwatcher_win.cpp @@ -332,12 +332,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, QStringList unhandled; for (const QString &path : paths) { auto sg = qScopeGuard([&] { unhandled.push_back(path); }); - QString normalPath = path; - if ((normalPath.endsWith(u'/') && !normalPath.endsWith(":/"_L1)) - || (normalPath.endsWith(u'\\') && !normalPath.endsWith(":\\"_L1))) { - normalPath.chop(1); - } - QFileInfo fileInfo(normalPath); + QFileInfo fileInfo(path); fileInfo.stat(); if (!fileInfo.exists()) continue; @@ -351,7 +346,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, continue; } - DEBUG() << "Looking for a thread/handle for" << normalPath; + DEBUG() << "Looking for a thread/handle for" << fileInfo.path(); const QString absolutePath = isDir ? fileInfo.absoluteFilePath() : fileInfo.absolutePath(); const uint flags = isDir @@ -495,11 +490,8 @@ QStringList QWindowsFileSystemWatcherEngine::removePaths(const QStringList &path QStringList unhandled; for (const QString &path : paths) { auto sg = qScopeGuard([&] { unhandled.push_back(path); }); - QString normalPath = path; - if (normalPath.endsWith(u'/') || normalPath.endsWith(u'\\')) - normalPath.chop(1); - QFileInfo fileInfo(normalPath); - DEBUG() << "removing" << normalPath; + QFileInfo fileInfo(path); + DEBUG() << "removing" << fileInfo.path(); QString absolutePath = fileInfo.absoluteFilePath(); QList::iterator jt, end; end = threads.end(); diff --git a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp index 5acab6e4739..dfdf4e05c1e 100644 --- a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp +++ b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp @@ -396,8 +396,14 @@ void tst_QFileSystemWatcher::addPaths() QFileSystemWatcher watcher; QStringList paths; paths << QDir::homePath() << QDir::tempPath(); +#ifndef Q_OS_QNX + // Adding this makes QNX fail and we haven't investigated why + for (const QFileInfo &fi : QDir::drives()) + paths << fi.absoluteFilePath(); // on Unix, this will be just "/" +#endif + QCOMPARE(watcher.addPaths(paths), QStringList()); - QCOMPARE(watcher.directories().size(), 2); + QCOMPARE(watcher.directories().size(), paths.size()); // With empty list paths.clear(); @@ -464,8 +470,14 @@ void tst_QFileSystemWatcher::removePaths() QFileSystemWatcher watcher; QStringList paths; paths << QDir::homePath() << QDir::tempPath(); +#ifndef Q_OS_QNX + // Adding this makes QNX fail and we haven't investigated why + for (const QFileInfo &fi : QDir::drives()) + paths << fi.absoluteFilePath(); // on Unix, this will be just "/" +#endif + QCOMPARE(watcher.addPaths(paths), QStringList()); - QCOMPARE(watcher.directories().size(), 2); + QCOMPARE(watcher.directories().size(), paths.size()); QCOMPARE(watcher.removePaths(paths), QStringList()); QCOMPARE(watcher.directories().size(), 0); @@ -613,9 +625,11 @@ void tst_QFileSystemWatcher::nonExistingFile() QStringList() << "../..//./does-not-exist"); // empty path is not actually a failure + QTest::ignoreMessage(QtWarningMsg, "QFileSystemWatcher::addPaths: list is empty"); QCOMPARE(watcher.addPaths(QStringList() << QString()), QStringList()); // empty path is not actually a failure + QTest::ignoreMessage(QtWarningMsg, "QFileSystemWatcher::removePaths: list is empty"); QCOMPARE(watcher.removePaths(QStringList() << QString()), QStringList()); }