summaryrefslogtreecommitdiffstats
path: root/src/libs/kdtools/kdupdaterupdateoperations.cpp
diff options
context:
space:
mode:
authorTim Jenssen <tim.jenssen@digia.com>2013-06-14 10:16:52 +0200
committerTim Jenssen <tim.jenssen@digia.com>2013-06-14 10:23:15 +0200
commit1b4cd05fda315e96fccb828e0197f1f7143fe189 (patch)
tree3c9caeabe37d42c1fc01154aa7e95a7c9d285a08 /src/libs/kdtools/kdupdaterupdateoperations.cpp
parent009c715555ebb3bd6cde5a9b1daa4bf96f2b79af (diff)
parentf028c0dcc865933703a3db31f526bfe7b53d7f1b (diff)
Merge remote-tracking branch 'origin/1.3' into 1.4
Diffstat (limited to 'src/libs/kdtools/kdupdaterupdateoperations.cpp')
-rw-r--r--src/libs/kdtools/kdupdaterupdateoperations.cpp61
1 files changed, 42 insertions, 19 deletions
diff --git a/src/libs/kdtools/kdupdaterupdateoperations.cpp b/src/libs/kdtools/kdupdaterupdateoperations.cpp
index 484df9838..41f9ef289 100644
--- a/src/libs/kdtools/kdupdaterupdateoperations.cpp
+++ b/src/libs/kdtools/kdupdaterupdateoperations.cpp
@@ -45,6 +45,34 @@ static QString errnoToQString(int error)
#endif
}
+static bool removeDirectory(const QString &path, QString *errorString, bool force = true)
+{
+ Q_ASSERT(errorString);
+ const QFileInfoList entries = QDir(path).entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden);
+ for (QFileInfoList::const_iterator it = entries.constBegin(); it != entries.constEnd(); ++it) {
+ if (it->isDir() && !it->isSymLink()) {
+ removeDirectory(it->filePath(), errorString, force);
+ } else if (force) {
+ QFile f(it->filePath());
+ if (!f.remove())
+ return false;
+ }
+ }
+
+ // even remove some hidden, OS-created files in there
+#if defined Q_OS_MAC
+ QFile::remove(path + QLatin1String("/.DS_Store"));
+#elif defined Q_OS_WIN
+ QFile::remove(path + QLatin1String("/Thumbs.db"));
+#endif
+
+ errno = 0;
+ const bool success = QDir().rmdir(path);
+ if (errno)
+ *errorString = errnoToQString(errno);
+ return success;
+}
+
/*
* \internal
* Returns a filename for a temporary file based on \a templateName
@@ -394,9 +422,8 @@ void MkdirOperation::backup()
bool MkdirOperation::performOperation()
{
- // Requires only one parameter. That is the name of
- // the file to remove.
- const QStringList args = this->arguments();
+ // Requires only one parameter. That is the path which should be created
+ QStringList args = this->arguments();
if (args.count() != 1) {
setError(InvalidArguments);
setErrorString(tr("Invalid arguments: %1 arguments given, 1 expected.").arg(args.count()));
@@ -416,7 +443,10 @@ bool MkdirOperation::undoOperation()
{
Q_ASSERT(arguments().count() == 1);
- QDir createdDir = QDir(value(QLatin1String("createddir")).toString());
+ QString createdDirValue = value(QLatin1String("createddir")).toString();
+ if (createdDirValue.isEmpty())
+ createdDirValue = arguments().first();
+ QDir createdDir = QDir(createdDirValue);
const bool forceremoval = QVariant(value(QLatin1String("forceremoval"))).toBool();
// Since refactoring we know the mkdir operation which is creating the target path. If we do a full
@@ -430,23 +460,16 @@ bool MkdirOperation::undoOperation()
if (!createdDir.exists())
return true;
- if (forceremoval) {
- try {
- QInstaller::removeDirectory(createdDir.path());
- } catch (const QInstaller::Error &error) {
- setError(UserDefinedError, error.message());
- return false;
- }
- return true;
- }
+ QString errorString;
- // remove some hidden, OS-created files in there
- QInstaller::removeSystemGeneratedFiles(createdDir.path());
+ const bool result = removeDirectory(createdDir.path(), &errorString, forceremoval);
- errno = 0;
- const bool result = QDir::root().rmdir(createdDir.path());
- if (!result)
- setError(UserDefinedError, tr("Cannot remove directory %1: %2").arg(createdDir.path(), errnoToQString(errno)));
+ if (!result) {
+ if (errorString.isEmpty())
+ setError(UserDefinedError, tr("Cannot remove directory %1: %2").arg(createdDir.path(), errorString));
+ else
+ setError(UserDefinedError, tr("Cannot remove directory %1: %2").arg(createdDir.path(), errnoToQString(errno)));
+ }
return result;
}