From f77635883b0777fd7b852a40c2ef60955df4bf34 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 12 Oct 2023 15:10:29 +0200 Subject: [PATCH] Utils: avoid assert in FileWatcher Remove a file from the watcher while handling the fileChanged signal can lead into untracking the directory of the file before it got added to the watcher, so make sure it is tracked before emitting fileChanged. Change-Id: I63e80c20856af3d58ee23763180859f44f07b73d Reviewed-by: Christian Stenger --- src/libs/utils/filesystemwatcher.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/libs/utils/filesystemwatcher.cpp b/src/libs/utils/filesystemwatcher.cpp index 155f83fba03..d410ff2507f 100644 --- a/src/libs/utils/filesystemwatcher.cpp +++ b/src/libs/utils/filesystemwatcher.cpp @@ -428,13 +428,11 @@ QStringList FileSystemWatcher::directories() const void FileSystemWatcher::slotFileChanged(const QString &path) { const auto it = d->m_files.find(path); - QStringList toAdd; if (it != d->m_files.end() && it.value().trigger(path)) { qCDebug(fileSystemWatcherLog) << this << "triggers on file" << it.key() << it.value().watchMode << it.value().modifiedTime.toString(Qt::ISODate); - d->fileChanged(path); QFileInfo fi(path); if (!fi.exists()) { @@ -443,12 +441,10 @@ void FileSystemWatcher::slotFileChanged(const QString &path) Q_ASSERT(dirCount > 0); if (dirCount == 1) - toAdd << directory; + d->m_staticData->m_watcher->addPath(directory); } + d->fileChanged(path); } - - if (!toAdd.isEmpty()) - d->m_staticData->m_watcher->addPaths(toAdd); } void FileSystemWatcher::slotDirectoryChanged(const QString &path)