diff options
author | Tim Jenssen <tim.jenssen@qt.io> | 2017-06-26 12:39:52 +0200 |
---|---|---|
committer | Tobias Hunger <tobias.hunger@qt.io> | 2017-06-26 14:13:07 +0000 |
commit | 56db0df2e65f897a6d268a6e8e22bb543a56215d (patch) | |
tree | 2d39e561c3f7032cf0d8e39cb8b76f1624db12db | |
parent | 6ab1da8b78d9bac8ffb0ba8ced6dfef42511d521 (diff) |
Qbs: Fix crash when renaming files
Fix a crash when using file nodes to change the project. The methods used
to take const references, with the data living in the nodes of the project
tree. Since the methods change the project tree and thus cause the tree to
be rebuilt, the original data may get lost. So copy the data instead.
All the qbs::*Data classes are using shared data, so the overhead is not
too big.
Task-number: QTCREATORBUG-18440
Change-Id: I45ca5403a04e17790416dfe15b836f12c732e824
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r-- | dist/changes-4.3.1.md | 4 | ||||
-rw-r--r-- | src/plugins/qbsprojectmanager/qbsproject.cpp | 12 | ||||
-rw-r--r-- | src/plugins/qbsprojectmanager/qbsproject.h | 15 |
3 files changed, 20 insertions, 11 deletions
diff --git a/dist/changes-4.3.1.md b/dist/changes-4.3.1.md index fa1ac40afb..018f3a461d 100644 --- a/dist/changes-4.3.1.md +++ b/dist/changes-4.3.1.md @@ -43,6 +43,10 @@ CMake Projects * Fixed that building application failed first time and after build error when using CMake < 3.7 (QTCREATORBUG-18290, QTCREATORBUG-18382) +Qbs Projects + +* Fixed crash when renaming files (QTCREATORBUG-18440) + Autotools Projects * Fixed regressions in project tree (QTCREATORBUG-18371) diff --git a/src/plugins/qbsprojectmanager/qbsproject.cpp b/src/plugins/qbsprojectmanager/qbsproject.cpp index fe0980e01d..6496a66d31 100644 --- a/src/plugins/qbsprojectmanager/qbsproject.cpp +++ b/src/plugins/qbsprojectmanager/qbsproject.cpp @@ -237,8 +237,8 @@ bool QbsProject::ensureWriteableQbsFile(const QString &file) } bool QbsProject::addFilesToProduct(const QStringList &filePaths, - const qbs::ProductData &productData, - const qbs::GroupData &groupData, QStringList *notAdded) + const qbs::ProductData productData, + const qbs::GroupData groupData, QStringList *notAdded) { QTC_ASSERT(m_qbsProject.isValid(), return false); QStringList allPaths = groupData.allFilePaths(); @@ -262,8 +262,8 @@ bool QbsProject::addFilesToProduct(const QStringList &filePaths, } bool QbsProject::removeFilesFromProduct(const QStringList &filePaths, - const qbs::ProductData &productData, - const qbs::GroupData &groupData, + const qbs::ProductData productData, + const qbs::GroupData groupData, QStringList *notRemoved) { QTC_ASSERT(m_qbsProject.isValid(), return false); @@ -290,8 +290,8 @@ bool QbsProject::removeFilesFromProduct(const QStringList &filePaths, } bool QbsProject::renameFileInProduct(const QString &oldPath, const QString &newPath, - const qbs::ProductData &productData, - const qbs::GroupData &groupData) + const qbs::ProductData productData, + const qbs::GroupData groupData) { if (newPath.isEmpty()) return false; diff --git a/src/plugins/qbsprojectmanager/qbsproject.h b/src/plugins/qbsprojectmanager/qbsproject.h index a13fdf698a..505d70412a 100644 --- a/src/plugins/qbsprojectmanager/qbsproject.h +++ b/src/plugins/qbsprojectmanager/qbsproject.h @@ -66,14 +66,19 @@ public: QStringList filesGeneratedFrom(const QString &sourceFile) const override; bool isProjectEditable() const; - bool addFilesToProduct(const QStringList &filePaths, const qbs::ProductData &productData, - const qbs::GroupData &groupData, QStringList *notAdded); + // qbs::ProductData and qbs::GroupData are held by the nodes in the project tree. + // These methods change those trees and invalidate the lot, so pass in copies of + // the data we are interested in! + // The overhead is not as big as it seems at first glance: These all are handles + // for shared data. + bool addFilesToProduct(const QStringList &filePaths, const qbs::ProductData productData, + const qbs::GroupData groupData, QStringList *notAdded); bool removeFilesFromProduct(const QStringList &filePaths, - const qbs::ProductData &productData, const qbs::GroupData &groupData, + const qbs::ProductData productData, const qbs::GroupData groupData, QStringList *notRemoved); bool renameFileInProduct(const QString &oldPath, - const QString &newPath, const qbs::ProductData &productData, - const qbs::GroupData &groupData); + const QString &newPath, const qbs::ProductData productData, + const qbs::GroupData groupData); qbs::BuildJob *build(const qbs::BuildOptions &opts, QStringList products, QString &error); qbs::CleanJob *clean(const qbs::CleanOptions &opts); |