forked from qt-creator/qt-creator
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:
@@ -261,21 +261,24 @@ static void addFileInfo(IDocument *document, const QString &filePath,
|
|||||||
const QFileInfo fi(filePath);
|
const QFileInfo fi(filePath);
|
||||||
state.modified = fi.lastModified();
|
state.modified = fi.lastModified();
|
||||||
state.permissions = fi.permissions();
|
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)) {
|
if (!d->m_states.contains(filePathKey)) {
|
||||||
FileState state;
|
FileState state;
|
||||||
state.watchedFilePath = filePath;
|
state.watchedFilePath = filePath;
|
||||||
d->m_states.insert(filePathKey, state);
|
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"
|
qCDebug(log) << "adding (" << (isLink ? "link" : "full") << ") watch for"
|
||||||
<< state.watchedFilePath;
|
<< watchedFilePath;
|
||||||
QFileSystemWatcher *watcher = 0;
|
QFileSystemWatcher *watcher = 0;
|
||||||
if (isLink)
|
if (isLink)
|
||||||
watcher = d->linkWatcher();
|
watcher = d->linkWatcher();
|
||||||
else
|
else
|
||||||
watcher = d->fileWatcher();
|
watcher = d->fileWatcher();
|
||||||
watcher->addPath(state.watchedFilePath);
|
watcher->addPath(watchedFilePath);
|
||||||
}
|
|
||||||
|
|
||||||
d->m_states[filePathKey].lastUpdatedState.insert(document, state);
|
d->m_states[filePathKey].lastUpdatedState.insert(document, state);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user