From 0691350e14632dea6c12a2d37e605dc0628b4ceb Mon Sep 17 00:00:00 2001 From: gunnar Date: Tue, 22 Sep 2009 07:34:51 +0200 Subject: Fixed crash in QFileSystemWatcher for addPath(nonExistingFile) Reviewed-by: Eskil --- src/corelib/io/qfilesystemwatcher_fsevents.cpp | 6 ++++++ tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/corelib/io/qfilesystemwatcher_fsevents.cpp b/src/corelib/io/qfilesystemwatcher_fsevents.cpp index f648016..be2125a 100644 --- a/src/corelib/io/qfilesystemwatcher_fsevents.cpp +++ b/src/corelib/io/qfilesystemwatcher_fsevents.cpp @@ -223,6 +223,11 @@ QStringList QFSEventsFileSystemWatcherEngine::addPaths(const QStringList &paths, } } } + + if (!pathsToWatch && failedToAdd.size() == paths.size()) { + return failedToAdd; + } + if (CFArrayGetCount(tmpArray) > 0) { if (pathsToWatch) { CFArrayAppendArray(tmpArray, pathsToWatch, CFRangeMake(0, CFArrayGetCount(pathsToWatch))); @@ -230,6 +235,7 @@ QStringList QFSEventsFileSystemWatcherEngine::addPaths(const QStringList &paths, } pathsToWatch = CFArrayCreateCopy(kCFAllocatorDefault, tmpArray); } + FSEventStreamContext context = { 0, this, 0, 0, 0 }; fsStream = FSEventStreamCreate(kCFAllocatorDefault, QFSEventsFileSystemWatcherEngine::fseventsCallback, diff --git a/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp index 9ab9d79..489a1ed 100644 --- a/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp +++ b/tests/auto/qfilesystemwatcher/tst_qfilesystemwatcher.cpp @@ -77,6 +77,8 @@ private slots: void watchFileAndItsDirectory_data() { basicTest_data(); } void watchFileAndItsDirectory(); + void nonExistingFile(); + void cleanup(); private: QStringList do_force_engines; @@ -525,5 +527,13 @@ void tst_QFileSystemWatcher::cleanup() QDir().rmdir("testDir"); } +void tst_QFileSystemWatcher::nonExistingFile() +{ + // Don't crash... + QFileSystemWatcher watcher; + watcher.addPath("file_that_does_not_exist.txt"); + QVERIFY(true); +} + QTEST_MAIN(tst_QFileSystemWatcher) #include "tst_qfilesystemwatcher.moc" -- cgit v0.12