forked from qt-creator/qt-creator
ProjectExplorer: Fix possible crash when renaming files
An event loop might run during renameFiles(), so we cannot be sure that
the nodes still exist in the end.
Amends 05430afdcf
.
Task-number: QDS-14695
Change-Id: If93ea2bea525fc1d4a191e4feaa243399cba6957
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
committed by
Tim Jenssen
parent
2bfdd6856a
commit
b2abc6fa8e
@@ -2495,6 +2495,13 @@ FilePairs ProjectExplorerPlugin::renameFiles(
|
|||||||
= Utils::filtered(nodesAndNewFilePaths, [](const std::pair<Node *, FilePath> &elem) {
|
= Utils::filtered(nodesAndNewFilePaths, [](const std::pair<Node *, FilePath> &elem) {
|
||||||
return !elem.first->filePath().equalsCaseSensitive(elem.second);
|
return !elem.first->filePath().equalsCaseSensitive(elem.second);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// The same as above, for use when the nodes might no longer exist.
|
||||||
|
const QList<std::pair<FilePath, FilePath>> oldAndNewFilePathsFiltered
|
||||||
|
= Utils::transform(nodesAndNewFilePathsFiltered, [](const std::pair<Node *, FilePath> &p) {
|
||||||
|
return std::make_pair(p.first->filePath(), p.second);
|
||||||
|
});
|
||||||
|
|
||||||
FilePaths renamedOnly;
|
FilePaths renamedOnly;
|
||||||
FilePaths failedRenamings;
|
FilePaths failedRenamings;
|
||||||
const auto renameFile = [&failedRenamings](const Node *node, const FilePath &newFilePath) {
|
const auto renameFile = [&failedRenamings](const Node *node, const FilePath &newFilePath) {
|
||||||
@@ -2560,9 +2567,9 @@ FilePairs ProjectExplorerPlugin::renameFiles(
|
|||||||
}
|
}
|
||||||
|
|
||||||
FilePairs allRenamedFiles;
|
FilePairs allRenamedFiles;
|
||||||
for (const std::pair<Node *, FilePath> &candidate : nodesAndNewFilePathsFiltered) {
|
for (const std::pair<FilePath, FilePath> &candidate : oldAndNewFilePathsFiltered) {
|
||||||
if (!failedRenamings.contains(candidate.first->filePath()))
|
if (!failedRenamings.contains(candidate.first))
|
||||||
allRenamedFiles.emplaceBack(candidate.first->filePath(), candidate.second);
|
allRenamedFiles.emplaceBack(candidate.first, candidate.second);
|
||||||
}
|
}
|
||||||
emit instance()->filesRenamed(allRenamedFiles);
|
emit instance()->filesRenamed(allRenamedFiles);
|
||||||
return allRenamedFiles;
|
return allRenamedFiles;
|
||||||
|
Reference in New Issue
Block a user