diff options
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_inotify.cpp | 25 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_kqueue.cpp | 27 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_polling.cpp | 24 | ||||
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_win.cpp | 29 |
4 files changed, 52 insertions, 53 deletions
diff --git a/src/corelib/io/qfilesystemwatcher_inotify.cpp b/src/corelib/io/qfilesystemwatcher_inotify.cpp index 9d008947ba..5fb5685f42 100644 --- a/src/corelib/io/qfilesystemwatcher_inotify.cpp +++ b/src/corelib/io/qfilesystemwatcher_inotify.cpp @@ -46,6 +46,7 @@ #include <qdebug.h> #include <qfile.h> #include <qfileinfo.h> +#include <qscopeguard.h> #include <qsocketnotifier.h> #include <qvarlengtharray.h> @@ -268,12 +269,11 @@ QStringList QInotifyFileSystemWatcherEngine::addPaths(const QStringList &paths, QStringList *files, QStringList *directories) { - QStringList p = paths; - QMutableListIterator<QString> it(p); - while (it.hasNext()) { - QString path = it.next(); + QStringList unhandled; + for (const QString &path : paths) { QFileInfo fi(path); bool isDir = fi.isDir(); + auto sg = qScopeGuard([&]{ unhandled.push_back(path); }); if (isDir) { if (directories->contains(path)) continue; @@ -305,7 +305,7 @@ QStringList QInotifyFileSystemWatcherEngine::addPaths(const QStringList &paths, continue; } - it.remove(); + sg.dismiss(); int id = isDir ? -wd : wd; if (id < 0) { @@ -318,19 +318,19 @@ QStringList QInotifyFileSystemWatcherEngine::addPaths(const QStringList &paths, idToPath.insert(id, path); } - return p; + return unhandled; } QStringList QInotifyFileSystemWatcherEngine::removePaths(const QStringList &paths, QStringList *files, QStringList *directories) { - QStringList p = paths; - QMutableListIterator<QString> it(p); - while (it.hasNext()) { - QString path = it.next(); + QStringList unhandled; + for (const QString &path : paths) { int id = pathToID.take(path); + auto sg = qScopeGuard([&]{ unhandled.push_back(path); }); + // Multiple paths could be associated to the same watch descriptor // when a file is moved and added with the new name. // So we should find and delete the correct one by using @@ -349,7 +349,8 @@ QStringList QInotifyFileSystemWatcherEngine::removePaths(const QStringList &path inotify_rm_watch(inotifyFd, wd); } - it.remove(); + sg.dismiss(); + if (id < 0) { directories->removeAll(path); } else { @@ -357,7 +358,7 @@ QStringList QInotifyFileSystemWatcherEngine::removePaths(const QStringList &path } } - return p; + return unhandled; } void QInotifyFileSystemWatcherEngine::readFromInotify() diff --git a/src/corelib/io/qfilesystemwatcher_kqueue.cpp b/src/corelib/io/qfilesystemwatcher_kqueue.cpp index 423b88cb7f..c2028e3641 100644 --- a/src/corelib/io/qfilesystemwatcher_kqueue.cpp +++ b/src/corelib/io/qfilesystemwatcher_kqueue.cpp @@ -45,6 +45,7 @@ #include <qdebug.h> #include <qfile.h> +#include <qscopeguard.h> #include <qsocketnotifier.h> #include <qvarlengtharray.h> @@ -94,10 +95,9 @@ QStringList QKqueueFileSystemWatcherEngine::addPaths(const QStringList &paths, QStringList *files, QStringList *directories) { - QStringList p = paths; - QMutableListIterator<QString> it(p); - while (it.hasNext()) { - QString path = it.next(); + QStringList unhandled; + for (const QString &path : paths) { + auto sg = qScopeGuard([&]{unhandled.push_back(path);}); int fd; #if defined(O_EVTONLY) fd = qt_safe_open(QFile::encodeName(path), O_EVTONLY); @@ -149,7 +149,8 @@ QStringList QKqueueFileSystemWatcherEngine::addPaths(const QStringList &paths, continue; } - it.remove(); + sg.dismiss(); + if (id < 0) { DEBUG() << "QKqueueFileSystemWatcherEngine: added directory path" << path; directories->append(path); @@ -162,20 +163,19 @@ QStringList QKqueueFileSystemWatcherEngine::addPaths(const QStringList &paths, idToPath.insert(id, path); } - return p; + return unhandled; } QStringList QKqueueFileSystemWatcherEngine::removePaths(const QStringList &paths, QStringList *files, QStringList *directories) { - QStringList p = paths; if (pathToID.isEmpty()) - return p; + return paths; - QMutableListIterator<QString> it(p); - while (it.hasNext()) { - QString path = it.next(); + QStringList unhandled; + for (const QString &path : paths) { + auto sg = qScopeGuard([&]{unhandled.push_back(path);}); int id = pathToID.take(path); QString x = idToPath.take(id); if (x.isEmpty() || x != path) @@ -183,14 +183,15 @@ QStringList QKqueueFileSystemWatcherEngine::removePaths(const QStringList &paths ::close(id < 0 ? -id : id); - it.remove(); + sg.dismiss(); + if (id < 0) directories->removeAll(path); else files->removeAll(path); } - return p; + return unhandled; } void QKqueueFileSystemWatcherEngine::readFromKqueue() diff --git a/src/corelib/io/qfilesystemwatcher_polling.cpp b/src/corelib/io/qfilesystemwatcher_polling.cpp index 903c15f4a9..a95a48cc8f 100644 --- a/src/corelib/io/qfilesystemwatcher_polling.cpp +++ b/src/corelib/io/qfilesystemwatcher_polling.cpp @@ -38,6 +38,7 @@ ****************************************************************************/ #include "qfilesystemwatcher_polling_p.h" +#include <QtCore/qscopeguard.h> #include <QtCore/qtimer.h> QT_BEGIN_NAMESPACE @@ -53,10 +54,9 @@ QStringList QPollingFileSystemWatcherEngine::addPaths(const QStringList &paths, QStringList *files, QStringList *directories) { - QStringList p = paths; - QMutableListIterator<QString> it(p); - while (it.hasNext()) { - QString path = it.next(); + QStringList unhandled; + for (const QString &path : paths) { + auto sg = qScopeGuard([&]{ unhandled.push_back(path); }); QFileInfo fi(path); if (!fi.exists()) continue; @@ -73,7 +73,7 @@ QStringList QPollingFileSystemWatcherEngine::addPaths(const QStringList &paths, files->append(path); this->files.insert(path, fi); } - it.remove(); + sg.dismiss(); } if ((!this->files.isEmpty() || @@ -82,23 +82,21 @@ QStringList QPollingFileSystemWatcherEngine::addPaths(const QStringList &paths, timer.start(PollingInterval); } - return p; + return unhandled; } QStringList QPollingFileSystemWatcherEngine::removePaths(const QStringList &paths, QStringList *files, QStringList *directories) { - QStringList p = paths; - QMutableListIterator<QString> it(p); - while (it.hasNext()) { - QString path = it.next(); + QStringList unhandled; + for (const QString &path : paths) { if (this->directories.remove(path)) { directories->removeAll(path); - it.remove(); } else if (this->files.remove(path)) { files->removeAll(path); - it.remove(); + } else { + unhandled.push_back(path); } } @@ -107,7 +105,7 @@ QStringList QPollingFileSystemWatcherEngine::removePaths(const QStringList &path timer.stop(); } - return p; + return unhandled; } void QPollingFileSystemWatcherEngine::timeout() diff --git a/src/corelib/io/qfilesystemwatcher_win.cpp b/src/corelib/io/qfilesystemwatcher_win.cpp index eb626fd541..aadfe7963d 100644 --- a/src/corelib/io/qfilesystemwatcher_win.cpp +++ b/src/corelib/io/qfilesystemwatcher_win.cpp @@ -44,6 +44,7 @@ #include <qfileinfo.h> #include <qstringlist.h> #include <qset.h> +#include <qscopeguard.h> #include <qdatetime.h> #include <qdir.h> #include <qtextstream.h> @@ -377,10 +378,9 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, QStringList *directories) { DEBUG() << "Adding" << paths.count() << "to existing" << (files->count() + directories->count()) << "watchers"; - QStringList p = paths; - QMutableListIterator<QString> it(p); - while (it.hasNext()) { - QString path = it.next(); + QStringList unhandled; + for (const QString &path : paths) { + auto sg = qScopeGuard([&] { unhandled.push_back(path); }); QString normalPath = path; if ((normalPath.endsWith(QLatin1Char('/')) && !normalPath.endsWith(QLatin1String(":/"))) || (normalPath.endsWith(QLatin1Char('\\')) && !normalPath.endsWith(QLatin1String(":\\")))) { @@ -463,7 +463,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, else files->append(path); } - it.remove(); + sg.dismiss(); thread->wakeup(); break; } @@ -493,7 +493,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, else files->append(path); - it.remove(); + sg.dismiss(); found = true; thread->wakeup(); break; @@ -519,7 +519,7 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, thread->msg = '@'; thread->start(); threads.append(thread); - it.remove(); + sg.dismiss(); } } } @@ -527,12 +527,12 @@ QStringList QWindowsFileSystemWatcherEngine::addPaths(const QStringList &paths, #ifndef Q_OS_WINRT if (Q_LIKELY(m_driveListener)) { for (const QString &path : paths) { - if (!p.contains(path)) + if (!unhandled.contains(path)) m_driveListener->addPath(path); } } #endif // !Q_OS_WINRT - return p; + return unhandled; } QStringList QWindowsFileSystemWatcherEngine::removePaths(const QStringList &paths, @@ -540,10 +540,9 @@ QStringList QWindowsFileSystemWatcherEngine::removePaths(const QStringList &path QStringList *directories) { DEBUG() << "removePaths" << paths; - QStringList p = paths; - QMutableListIterator<QString> it(p); - while (it.hasNext()) { - QString path = it.next(); + QStringList unhandled; + for (const QString &path : paths) { + auto sg = qScopeGuard([&] { unhandled.push_back(path); }); QString normalPath = path; if (normalPath.endsWith(QLatin1Char('/')) || normalPath.endsWith(QLatin1Char('\\'))) normalPath.chop(1); @@ -572,7 +571,7 @@ QStringList QWindowsFileSystemWatcherEngine::removePaths(const QStringList &path // ### files->removeAll(path); directories->removeAll(path); - it.remove(); + sg.dismiss(); if (h.isEmpty()) { DEBUG() << "Closing handle" << handle.handle; @@ -613,7 +612,7 @@ QStringList QWindowsFileSystemWatcherEngine::removePaths(const QStringList &path } threads.removeAll(0); - return p; + return unhandled; } /////////// |