From 0a9427d03b174cf4a4f0fa41151688d0c227ba61 Mon Sep 17 00:00:00 2001 From: Katja Marttila Date: Tue, 6 Oct 2020 14:13:22 +0300 Subject: 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 --- src/libs/installer/packagemanagercore_p.cpp | 2 ++ src/libs/kdtools/updateoperations.cpp | 24 ++++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp index 7ed6d5a29..8b08c3be1 100644 --- a/src/libs/installer/packagemanagercore_p.cpp +++ b/src/libs/installer/packagemanagercore_p.cpp @@ -1891,12 +1891,14 @@ bool PackageManagerCorePrivate::runUninstaller() deleteMaintenanceTool(); // this will also delete the TargetDir on Windows // If not on Windows, we need to remove TargetDir manually. +#ifndef Q_OS_WIN if (QVariant(m_core->value(scRemoveTargetDir)).toBool() && !targetDir().isEmpty()) { if (updateAdminRights && !adminRightsGained) adminRightsGained = m_core->gainAdminRights(); removeDirectoryThreaded(targetDir(), true); qCDebug(QInstaller::lcInstallerInstallLog) << "Complete uninstallation was chosen."; } +#endif unregisterMaintenanceTool(); m_needToWriteMaintenanceTool = false; 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()) -- cgit v1.2.3