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 05485071b0

Task-number: QTCREATORBUG-18892
Change-Id: I3b216d614b9f82e308da63c07d990e5911193655
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Eike Ziller
2017-09-28 15:45:54 +02:00
parent fc4bc59fd5
commit e0639d0696

View File

@@ -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);
}
// 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"
<< state.watchedFilePath;
<< watchedFilePath;
QFileSystemWatcher *watcher = 0;
if (isLink)
watcher = d->linkWatcher();
else
watcher = d->fileWatcher();
watcher->addPath(state.watchedFilePath);
}
watcher->addPath(watchedFilePath);
d->m_states[filePathKey].lastUpdatedState.insert(document, state);
}