forked from qt-creator/qt-creator
Maemo: Fix code redundancy.
Recursively removing a directory was implmented twice.
This commit is contained in:
@@ -29,8 +29,12 @@
|
||||
|
||||
#include "maemoglobal.h"
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QString>
|
||||
|
||||
#define TR(text) QCoreApplication::translate("Qt4ProjectManager::Internal::MaemoGlobal", text)
|
||||
|
||||
namespace Qt4ProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
@@ -71,5 +75,32 @@ QString MaemoGlobal::remoteEnvironment(const QList<Utils::EnvironmentItem> &list
|
||||
return env.mid(0, env.size() - 1);
|
||||
}
|
||||
|
||||
bool MaemoGlobal::removeRecursively(const QString &filePath, QString &error)
|
||||
{
|
||||
QFileInfo fileInfo(filePath);
|
||||
if (fileInfo.isDir()) {
|
||||
QDir dir(filePath);
|
||||
QStringList fileNames = dir.entryList(QDir::Files | QDir::Hidden
|
||||
| QDir::System | QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
foreach (const QString &fileName, fileNames) {
|
||||
if (!removeRecursively(filePath + QLatin1Char('/') + fileName, error))
|
||||
return false;
|
||||
}
|
||||
dir.cdUp();
|
||||
if (!dir.rmdir(fileInfo.fileName())) {
|
||||
error = TR("Failed to remove directory '%1'.")
|
||||
.arg(QDir::toNativeSeparators(filePath));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!QFile::remove(filePath)) {
|
||||
error = TR("Failed to remove file '%1'.")
|
||||
.arg(QDir::toNativeSeparators(filePath));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Qt4ProjectManager
|
||||
|
||||
@@ -57,6 +57,8 @@ public:
|
||||
static QString remoteEnvironment(const QList<Utils::EnvironmentItem> &list);
|
||||
static QString remoteSourceProfilesCommand();
|
||||
|
||||
static bool removeRecursively(const QString &filePath, QString &error);
|
||||
|
||||
template<class T> static T *buildStep(const ProjectExplorer::DeployConfiguration *dc)
|
||||
{
|
||||
ProjectExplorer::BuildStepList *bsl = dc->stepList();
|
||||
|
||||
@@ -230,9 +230,10 @@ bool MaemoPackageCreationStep::copyDebianFiles(bool inSourceBuild)
|
||||
.arg(QDir::toNativeSeparators(debianDirPath)));
|
||||
return false;
|
||||
}
|
||||
if (!removeDirectory(debianDirPath)) {
|
||||
QString error;
|
||||
if (!MaemoGlobal::removeRecursively(debianDirPath, error)) {
|
||||
raiseError(tr("Packaging failed."),
|
||||
tr("Could not remove directory '%1'.").arg(debianDirPath));
|
||||
tr("Could not remove directory '%1': %2").arg(debianDirPath, error));
|
||||
return false;
|
||||
}
|
||||
QDir buildDir(buildDirectory());
|
||||
@@ -271,29 +272,6 @@ bool MaemoPackageCreationStep::copyDebianFiles(bool inSourceBuild)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MaemoPackageCreationStep::removeDirectory(const QString &dirPath)
|
||||
{
|
||||
QDir dir(dirPath);
|
||||
if (!dir.exists())
|
||||
return true;
|
||||
|
||||
const QStringList &files
|
||||
= dir.entryList(QDir::Files | QDir::Hidden | QDir::System);
|
||||
foreach (const QString &fileName, files) {
|
||||
if (!dir.remove(fileName))
|
||||
return false;
|
||||
}
|
||||
|
||||
const QStringList &subDirs
|
||||
= dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
foreach (const QString &subDirName, subDirs) {
|
||||
if (!removeDirectory(dirPath + QLatin1Char('/') + subDirName))
|
||||
return false;
|
||||
}
|
||||
|
||||
return dir.rmdir(dirPath);
|
||||
}
|
||||
|
||||
bool MaemoPackageCreationStep::runCommand(QProcess *buildProc,
|
||||
const QString &command)
|
||||
{
|
||||
|
||||
@@ -84,7 +84,6 @@ public:
|
||||
static QString packageName(const ProjectExplorer::Project *project);
|
||||
static QString packageFileName(const ProjectExplorer::Project *project,
|
||||
const QString &version);
|
||||
static bool removeDirectory(const QString &dirPath);
|
||||
|
||||
QString projectName() const;
|
||||
|
||||
|
||||
@@ -105,8 +105,9 @@ void MaemoPublisherFremantleFree::createPackage()
|
||||
+ m_project->displayName();
|
||||
if (QFileInfo(tmpDirContainer()).exists()) {
|
||||
emit progressReport(tr("Removing left-over temporary directory ..."));
|
||||
if (!removeRecursively(tmpDirContainer())) {
|
||||
finishWithFailure(tr("Error: Could not remove temporary directory."),
|
||||
QString error;
|
||||
if (!MaemoGlobal::removeRecursively(tmpDirContainer(), error)) {
|
||||
finishWithFailure(tr("Error removing temporary directory: %1").arg(error),
|
||||
tr("Publishing failed: Could not create source package."));
|
||||
return;
|
||||
}
|
||||
@@ -140,34 +141,6 @@ void MaemoPublisherFremantleFree::createPackage()
|
||||
+ pp->effectiveArguments());
|
||||
}
|
||||
|
||||
// TODO: The same exists in packaging step. Move to MaemoGlobal.
|
||||
bool MaemoPublisherFremantleFree::removeRecursively(const QString &filePath)
|
||||
{
|
||||
QFileInfo fileInfo(filePath);
|
||||
if (fileInfo.isDir()) {
|
||||
QDir dir(filePath);
|
||||
QStringList fileNames = dir.entryList(QDir::Files | QDir::Hidden
|
||||
| QDir::System | QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
foreach (const QString &fileName, fileNames) {
|
||||
if (!removeRecursively(filePath + QLatin1Char('/') + fileName))
|
||||
return false;
|
||||
}
|
||||
dir.cdUp();
|
||||
if (!dir.rmdir(fileInfo.fileName())) {
|
||||
emit progressReport(tr("Failed to remove directory '%1'.")
|
||||
.arg(QDir::toNativeSeparators(filePath)));
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!QFile::remove(filePath)) {
|
||||
emit progressReport(tr("Failed to remove file '%1'.")
|
||||
.arg(QDir::toNativeSeparators(filePath)), ErrorOutput);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MaemoPublisherFremantleFree::copyRecursively(const QString &srcFilePath,
|
||||
const QString &tgtFilePath)
|
||||
{
|
||||
@@ -329,9 +302,11 @@ void MaemoPublisherFremantleFree::runDpkgBuildPackage()
|
||||
return;
|
||||
}
|
||||
foreach (const QString &filePath, d.filesToExclude()) {
|
||||
if (!removeRecursively(filePath))
|
||||
finishWithFailure(QString(),
|
||||
QString error;
|
||||
if (!MaemoGlobal::removeRecursively(filePath, error)) {
|
||||
finishWithFailure(error,
|
||||
tr("Publishing failed: Could not create package."));
|
||||
}
|
||||
}
|
||||
|
||||
if (m_state == Inactive)
|
||||
|
||||
@@ -88,7 +88,6 @@ private:
|
||||
void setState(State newState);
|
||||
void createPackage();
|
||||
void uploadPackage();
|
||||
bool removeRecursively(const QString &filePath);
|
||||
bool copyRecursively(const QString &srcFilePath,
|
||||
const QString &tgtFilePath);
|
||||
void handleProcessFinished(bool failedToStart);
|
||||
|
||||
@@ -171,7 +171,8 @@ bool MaemoTemplatesManager::createDebianTemplatesIfNecessary(const ProjectExplor
|
||||
|
||||
const QString dhMakeDebianDir = projectDir.path() + QLatin1Char('/')
|
||||
+ PackagingDirName + QLatin1String("/debian");
|
||||
MaemoPackageCreationStep::removeDirectory(dhMakeDebianDir);
|
||||
QString removeError;
|
||||
MaemoGlobal::removeRecursively(dhMakeDebianDir, removeError);
|
||||
const QString command = QLatin1String("dh_make -s -n -p ")
|
||||
+ MaemoPackageCreationStep::packageName(project) + QLatin1Char('_')
|
||||
+ MaemoPackageCreationStep::DefaultVersionNumber;
|
||||
@@ -193,7 +194,7 @@ bool MaemoTemplatesManager::createDebianTemplatesIfNecessary(const ProjectExplor
|
||||
if (!QFile::rename(dhMakeDebianDir, debianDirPath(project))) {
|
||||
raiseError(tr("Unable to move new debian directory to '%1'.")
|
||||
.arg(QDir::toNativeSeparators(debianDirPath(project))));
|
||||
MaemoPackageCreationStep::removeDirectory(dhMakeDebianDir);
|
||||
MaemoGlobal::removeRecursively(dhMakeDebianDir, removeError);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user