forked from qt-creator/qt-creator
QbsProjectManager: Write enable project files before adding/removing
Prevent failures in situations where Qbs project files are still write protected, like e.g. in Perforce VCS. Change-Id: I2828546adcc314b7c6b0b6720e1cf96733d62fa5 Reviewed-by: Christian Kandeler <christian.kandeler@digia.com>
This commit is contained in:
committed by
Christian Kandeler
parent
14fe8f07cd
commit
9d95afc803
@@ -39,6 +39,9 @@
|
|||||||
#include <coreplugin/documentmanager.h>
|
#include <coreplugin/documentmanager.h>
|
||||||
#include <coreplugin/icontext.h>
|
#include <coreplugin/icontext.h>
|
||||||
#include <coreplugin/id.h>
|
#include <coreplugin/id.h>
|
||||||
|
#include <coreplugin/icore.h>
|
||||||
|
#include <coreplugin/iversioncontrol.h>
|
||||||
|
#include <coreplugin/vcsmanager.h>
|
||||||
#include <coreplugin/messagemanager.h>
|
#include <coreplugin/messagemanager.h>
|
||||||
#include <coreplugin/progressmanager/progressmanager.h>
|
#include <coreplugin/progressmanager/progressmanager.h>
|
||||||
#include <coreplugin/mimedatabase.h>
|
#include <coreplugin/mimedatabase.h>
|
||||||
@@ -68,6 +71,7 @@
|
|||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QMessageBox>
|
||||||
#include <QVariantMap>
|
#include <QVariantMap>
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
@@ -229,6 +233,27 @@ private:
|
|||||||
bool m_wasInDocumentManager;
|
bool m_wasInDocumentManager;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool QbsProject::ensureWriteableQbsFile(const QString &file)
|
||||||
|
{
|
||||||
|
// Ensure that the file is not read only
|
||||||
|
QFileInfo fi(file);
|
||||||
|
if (!fi.isWritable()) {
|
||||||
|
// Try via vcs manager
|
||||||
|
Core::IVersionControl *versionControl =
|
||||||
|
Core::VcsManager::findVersionControlForDirectory(fi.absolutePath());
|
||||||
|
if (!versionControl || !versionControl->vcsOpen(file)) {
|
||||||
|
bool makeWritable = QFile::setPermissions(file, fi.permissions() | QFile::WriteUser);
|
||||||
|
if (!makeWritable) {
|
||||||
|
QMessageBox::warning(Core::ICore::mainWindow(),
|
||||||
|
tr("Failed!"),
|
||||||
|
tr("Could not write project file %1.").arg(file));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool QbsProject::addFilesToProduct(QbsBaseProjectNode *node, const QStringList &filePaths,
|
bool QbsProject::addFilesToProduct(QbsBaseProjectNode *node, const QStringList &filePaths,
|
||||||
const qbs::ProductData &productData, const qbs::GroupData &groupData, QStringList *notAdded)
|
const qbs::ProductData &productData, const qbs::GroupData &groupData, QStringList *notAdded)
|
||||||
{
|
{
|
||||||
@@ -236,6 +261,7 @@ bool QbsProject::addFilesToProduct(QbsBaseProjectNode *node, const QStringList &
|
|||||||
QStringList allPaths = groupData.allFilePaths();
|
QStringList allPaths = groupData.allFilePaths();
|
||||||
const QString productFilePath = productData.location().fileName();
|
const QString productFilePath = productData.location().fileName();
|
||||||
ChangeExpector expector(productFilePath, m_qbsDocuments);
|
ChangeExpector expector(productFilePath, m_qbsDocuments);
|
||||||
|
ensureWriteableQbsFile(productFilePath);
|
||||||
foreach (const QString &path, filePaths) {
|
foreach (const QString &path, filePaths) {
|
||||||
qbs::ErrorInfo err = m_qbsProject.addFiles(productData, groupData, QStringList() << path);
|
qbs::ErrorInfo err = m_qbsProject.addFiles(productData, groupData, QStringList() << path);
|
||||||
if (err.hasError()) {
|
if (err.hasError()) {
|
||||||
@@ -261,6 +287,7 @@ bool QbsProject::removeFilesFromProduct(QbsBaseProjectNode *node, const QStringL
|
|||||||
QStringList allPaths = groupData.allFilePaths();
|
QStringList allPaths = groupData.allFilePaths();
|
||||||
const QString productFilePath = productData.location().fileName();
|
const QString productFilePath = productData.location().fileName();
|
||||||
ChangeExpector expector(productFilePath, m_qbsDocuments);
|
ChangeExpector expector(productFilePath, m_qbsDocuments);
|
||||||
|
ensureWriteableQbsFile(productFilePath);
|
||||||
foreach (const QString &path, filePaths) {
|
foreach (const QString &path, filePaths) {
|
||||||
qbs::ErrorInfo err
|
qbs::ErrorInfo err
|
||||||
= m_qbsProject.removeFiles(productData, groupData, QStringList() << path);
|
= m_qbsProject.removeFiles(productData, groupData, QStringList() << path);
|
||||||
|
|||||||
@@ -135,6 +135,8 @@ private:
|
|||||||
void updateDeploymentInfo(const qbs::Project &project);
|
void updateDeploymentInfo(const qbs::Project &project);
|
||||||
void updateBuildTargetData();
|
void updateBuildTargetData();
|
||||||
|
|
||||||
|
static bool ensureWriteableQbsFile(const QString &file);
|
||||||
|
|
||||||
QbsManager *const m_manager;
|
QbsManager *const m_manager;
|
||||||
const QString m_projectName;
|
const QString m_projectName;
|
||||||
const QString m_fileName;
|
const QString m_fileName;
|
||||||
|
|||||||
Reference in New Issue
Block a user