Maemo: Fix code redundancy.

Recursively removing a directory was implmented twice.
This commit is contained in:
Christian Kandeler
2010-11-26 12:19:32 +01:00
parent ded9ed66ef
commit 7fd0b2dbb6
7 changed files with 46 additions and 61 deletions

View File

@@ -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