From bf440c18bb60a6964b32778157db2a22b168e946 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 9 Jun 2015 09:53:18 +0200 Subject: Fix return value of QWindowsFileSystemWatcherEngine::removePaths(). Previously, the path was removed from list returned (indicating failure to remove) only when the thread's list was empty (last file in directory). Move the statement up so that removal happens when it is found in thread's list. Task-number: QTBUG-46449 Change-Id: Ib79199c731f79357b0e5c17636254fbeb3a754a0 Reviewed-by: Robin Burchell --- src/corelib/io/qfilesystemwatcher_win.cpp | 3 +-- .../qfilesystemwatcher/tst_qfilesystemwatcher.cpp | 26 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/corelib/io/qfilesystemwatcher_win.cpp b/src/corelib/io/qfilesystemwatcher_win.cpp index 039992adba..4907a20a5f 100644 --- a/src/corelib/io/qfilesystemwatcher_win.cpp +++ b/src/corelib/io/qfilesystemwatcher_win.cpp @@ -248,6 +248,7 @@ QStringList QWindowsFileSystemWatcherEngine::removePaths(const QStringList &path // ### files->removeAll(path); directories->removeAll(path); + it.remove(); if (h.isEmpty()) { DEBUG() << "Closing handle" << handle.handle; @@ -260,8 +261,6 @@ QStringList QWindowsFileSystemWatcherEngine::removePaths(const QStringList &path thread->handleForDir.remove(QFileSystemWatcherPathKey(absolutePath)); // h is now invalid - it.remove(); - if (thread->handleForDir.isEmpty()) { DEBUG() << "Stopping thread " << thread; locker.unlock(); diff --git a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp index 0ebfd2ae35..7e56ecaab3 100644 --- a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp +++ b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp @@ -62,6 +62,7 @@ private slots: void removePath(); void addPaths(); void removePaths(); + void removePathsFilesInSameDirectory(); void watchFileAndItsDirectory_data() { basicTest_data(); } void watchFileAndItsDirectory(); @@ -460,6 +461,31 @@ void tst_QFileSystemWatcher::removePaths() watcher.removePaths(paths); } +void tst_QFileSystemWatcher::removePathsFilesInSameDirectory() +{ + // QTBUG-46449/Windows: Check the return values of removePaths(). + // When adding the 1st file, a thread is started to watch the temp path. + // After adding and removing the 2nd file, the thread is still running and + // success should be reported. + QTemporaryFile file1(m_tempDirPattern); + QTemporaryFile file2(m_tempDirPattern); + QVERIFY2(file1.open(), qPrintable(file1.errorString())); + QVERIFY2(file2.open(), qPrintable(file1.errorString())); + const QString path1 = file1.fileName(); + const QString path2 = file2.fileName(); + file1.close(); + file2.close(); + QFileSystemWatcher watcher; + QVERIFY(watcher.addPath(path1)); + QCOMPARE(watcher.files().size(), 1); + QVERIFY(watcher.addPath(path2)); + QCOMPARE(watcher.files().size(), 2); + QVERIFY(watcher.removePath(path1)); + QCOMPARE(watcher.files().size(), 1); + QVERIFY(watcher.removePath(path2)); + QCOMPARE(watcher.files().size(), 0); +} + static QByteArray msgFileOperationFailed(const char *what, const QFile &f) { return what + QByteArrayLiteral(" failed on \"") -- cgit v1.2.3