diff --git a/autotests/kdirwatch_unittest.cpp b/autotests/kdirwatch_unittest.cpp --- a/autotests/kdirwatch_unittest.cpp +++ b/autotests/kdirwatch_unittest.cpp @@ -112,6 +112,7 @@ void nestedEventLoop(); void testHardlinkChange(); void stopAndRestart(); + void shouldIgnoreQrcPaths(); protected Q_SLOTS: // internal slots void nestedEventLoopSlot(); @@ -749,4 +750,27 @@ QFile::remove(file3); } +void KDirWatch_UnitTest::shouldIgnoreQrcPaths() +{ + const auto oldCwd = QDir::currentPath(); + QVERIFY(QDir::setCurrent(QDir::homePath())); + + KDirWatch watch; + watch.addDir(QDir::homePath()); + // NOTE: addDir(".") it's not enough, we really need this path to trigger bug #374075. + watch.addDir(QStringLiteral(":/kio5/newfile-templates")); + + QSignalSpy dirtySpy(&watch, &KDirWatch::dirty); + + QFile file(QStringLiteral("bug374075.txt")); + QVERIFY(file.open(QIODevice::WriteOnly)); + QVERIFY(file.write(QByteArrayLiteral("test"))); + file.close(); + QVERIFY(file.exists()); + QVERIFY(dirtySpy.wait()); + QVERIFY(dirtySpy.count() > 0); + QVERIFY(file.remove()); + QVERIFY(QDir::setCurrent(oldCwd)); +} + #include "kdirwatch_unittest.moc" diff --git a/src/lib/io/kdirwatch.cpp b/src/lib/io/kdirwatch.cpp --- a/src/lib/io/kdirwatch.cpp +++ b/src/lib/io/kdirwatch.cpp @@ -791,6 +791,10 @@ Entry *sub_entry, bool isDir, KDirWatch::WatchModes watchModes) { QString path(_path); + if (path.startsWith(QLatin1String(":/"))) { + qCWarning(KDIRWATCH) << "Cannot watch QRC-like path" << path; + return; + } if (path.isEmpty() #ifndef Q_OS_WIN || path == QLatin1String("/dev")