summaryrefslogtreecommitdiffstats
path: root/src/libs/kdtools/updateoperations.cpp
diff options
context:
space:
mode:
authorKatja Marttila <katja.marttila@qt.io>2020-10-06 14:13:22 +0300
committerKatja Marttila <katja.marttila@qt.io>2020-10-15 10:46:08 +0300
commit0a9427d03b174cf4a4f0fa41151688d0c227ba61 (patch)
treeec14f991a0218bad674843ec6d3ae3028f884c8b /src/libs/kdtools/updateoperations.cpp
parent9f94110b7de18870d690d8ad102d26deceb17e0e (diff)
Don't warn if maintenance tool cannot be deleted
We have a deferred delete for maintenance tool as in Windows the running program cannot be deleted. Task-number: QTIFW-1979 Change-Id: I3bfd98dd1d476450b9b770c9b2f1c70810e67492 Reviewed-by: Arttu Tarkiainen <arttu.tarkiainen@qt.io>
Diffstat (limited to 'src/libs/kdtools/updateoperations.cpp')
-rw-r--r--src/libs/kdtools/updateoperations.cpp24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/libs/kdtools/updateoperations.cpp b/src/libs/kdtools/updateoperations.cpp
index efd499d6d..9301d4f13 100644
--- a/src/libs/kdtools/updateoperations.cpp
+++ b/src/libs/kdtools/updateoperations.cpp
@@ -54,7 +54,7 @@ static QString errnoToQString(int error)
#endif
}
-static bool removeDirectory(const QString &path, QString *errorString, bool force)
+static bool removeDirectory(const QString &path, QString *errorString, bool force, const QStringList &ignoreFiles = QStringList())
{
Q_ASSERT(errorString);
@@ -62,7 +62,9 @@ static bool removeDirectory(const QString &path, QString *errorString, bool forc
const QFileInfoList entries = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden);
foreach (const QFileInfo &entry, entries) {
if (entry.isDir() && (!entry.isSymLink()))
- removeDirectory(entry.filePath(), errorString, force);
+ removeDirectory(entry.filePath(), errorString, force, ignoreFiles);
+ else if (ignoreFiles.contains(entry.absoluteFilePath()))
+ continue;
else if (force && (!QFile(entry.filePath()).remove()))
return false;
}
@@ -72,6 +74,12 @@ static bool removeDirectory(const QString &path, QString *errorString, bool forc
errno = 0;
const bool success = dir.rmdir(path);
+
+ if (!success && (dir.entryList(QDir::NoDotAndDotDot | QDir::AllEntries | QDir::Hidden).count()
+ == ignoreFiles.count())){
+ return true;
+ }
+
if (errno)
*errorString = errnoToQString(errno);
return success;
@@ -500,8 +508,16 @@ bool MkdirOperation::undoOperation()
// Since refactoring we know the mkdir operation which is creating the target path. If we do a full
// uninstall prevent removing the full path including target, instead remove the target only. (QTIFW-46)
- if (hasValue(QLatin1String("uninstall-only")) && value(QLatin1String("uninstall-only")).toBool())
+ QStringList excludeFiles;
+ if (hasValue(QLatin1String("uninstall-only")) && value(QLatin1String("uninstall-only")).toBool()) {
createdDir = QDir(arguments().first());
+ // Do not try to remove maintenancetool in Windows as it will fail as it is running.
+ // In Windows we use deferred delete for maintenancetool.
+ #ifdef Q_OS_WIN
+ if (packageManager())
+ excludeFiles << packageManager()->maintenanceToolName();
+ #endif
+ }
if (createdDir == QDir::root())
return true;
@@ -511,7 +527,7 @@ bool MkdirOperation::undoOperation()
QString errorString;
- const bool result = removeDirectory(createdDir.path(), &errorString, forceremoval);
+ const bool result = removeDirectory(createdDir.path(), &errorString, forceremoval, excludeFiles);
if (!result) {
if (errorString.isEmpty())