Commit 56db0df2 authored by Tim Jenssen's avatar Tim Jenssen Committed by Tobias Hunger

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's avatarEike Ziller <eike.ziller@qt.io>
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
Reviewed-by: Christian Kandeler's avatarChristian Kandeler <christian.kandeler@qt.io>
parent 6ab1da8b
......@@ -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)
......
......@@ -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;
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment