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
|
||||
|
||||
Reference in New Issue
Block a user