From e0639d0696cdac7babc31893a7f5d65619ec7b85 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 28 Sep 2017 15:45:54 +0200 Subject: [PATCH] Fix reload issues for files with multiple registered documents If a file is removed, the file system watcher can loose its watch on it (e.g. on Linux, inode-based). Saving files does so "safely" by writing a temporary file, moving the original, and moving the new file in its place, which is triggering the issue above. That is why we need to re-register the path in the file system watcher. This broke in the refactoring done by 05485071b06cd34a9c55c584ef9e0984bca54c51 Task-number: QTCREATORBUG-18892 Change-Id: I3b216d614b9f82e308da63c07d990e5911193655 Reviewed-by: Tobias Hunger --- src/plugins/coreplugin/documentmanager.cpp | 23 ++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/plugins/coreplugin/documentmanager.cpp b/src/plugins/coreplugin/documentmanager.cpp index afbc8da18a0..536252845d5 100644 --- a/src/plugins/coreplugin/documentmanager.cpp +++ b/src/plugins/coreplugin/documentmanager.cpp @@ -261,21 +261,24 @@ static void addFileInfo(IDocument *document, const QString &filePath, const QFileInfo fi(filePath); state.modified = fi.lastModified(); state.permissions = fi.permissions(); - // Add watcher if we don't have that already + // Add state if we don't have already if (!d->m_states.contains(filePathKey)) { FileState state; state.watchedFilePath = filePath; d->m_states.insert(filePathKey, state); - - qCDebug(log) << "adding (" << (isLink ? "link" : "full") << ") watch for" - << state.watchedFilePath; - QFileSystemWatcher *watcher = 0; - if (isLink) - watcher = d->linkWatcher(); - else - watcher = d->fileWatcher(); - watcher->addPath(state.watchedFilePath); } + // Add or update watcher on file path + // This is also used to update the watcher in case of saved (==replaced) files or + // update link targets, even if there are multiple documents registered for it + const QString watchedFilePath = d->m_states.value(filePathKey).watchedFilePath; + qCDebug(log) << "adding (" << (isLink ? "link" : "full") << ") watch for" + << watchedFilePath; + QFileSystemWatcher *watcher = 0; + if (isLink) + watcher = d->linkWatcher(); + else + watcher = d->fileWatcher(); + watcher->addPath(watchedFilePath); d->m_states[filePathKey].lastUpdatedState.insert(document, state); }