diff options
Diffstat (limited to 'src/corelib/io/qfilesystemwatcher_inotify.cpp')
-rw-r--r-- | src/corelib/io/qfilesystemwatcher_inotify.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/src/corelib/io/qfilesystemwatcher_inotify.cpp b/src/corelib/io/qfilesystemwatcher_inotify.cpp index a5e629b646..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() @@ -388,7 +389,7 @@ void QInotifyFileSystemWatcherEngine::readFromInotify() const inotify_event &event = **it; ++it; - // qDebug() << "inotify event, wd" << event.wd << "mask" << hex << event.mask; + // qDebug() << "inotify event, wd" << event.wd << "mask" << Qt::hex << event.mask; int id = event.wd; QString path = getPathFromID(id); |