forked from qt-creator/qt-creator
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 <christian.stenger@qt.io>
This commit is contained in:
@@ -428,13 +428,11 @@ QStringList FileSystemWatcher::directories() const
|
|||||||
void FileSystemWatcher::slotFileChanged(const QString &path)
|
void FileSystemWatcher::slotFileChanged(const QString &path)
|
||||||
{
|
{
|
||||||
const auto it = d->m_files.find(path);
|
const auto it = d->m_files.find(path);
|
||||||
QStringList toAdd;
|
|
||||||
if (it != d->m_files.end() && it.value().trigger(path)) {
|
if (it != d->m_files.end() && it.value().trigger(path)) {
|
||||||
qCDebug(fileSystemWatcherLog)
|
qCDebug(fileSystemWatcherLog)
|
||||||
<< this << "triggers on file" << it.key()
|
<< this << "triggers on file" << it.key()
|
||||||
<< it.value().watchMode
|
<< it.value().watchMode
|
||||||
<< it.value().modifiedTime.toString(Qt::ISODate);
|
<< it.value().modifiedTime.toString(Qt::ISODate);
|
||||||
d->fileChanged(path);
|
|
||||||
|
|
||||||
QFileInfo fi(path);
|
QFileInfo fi(path);
|
||||||
if (!fi.exists()) {
|
if (!fi.exists()) {
|
||||||
@@ -443,12 +441,10 @@ void FileSystemWatcher::slotFileChanged(const QString &path)
|
|||||||
Q_ASSERT(dirCount > 0);
|
Q_ASSERT(dirCount > 0);
|
||||||
|
|
||||||
if (dirCount == 1)
|
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)
|
void FileSystemWatcher::slotDirectoryChanged(const QString &path)
|
||||||
|
Reference in New Issue
Block a user