diff options
author | Katja Marttila <katja.marttila@qt.io> | 2022-03-07 17:40:01 +0200 |
---|---|---|
committer | Katja Marttila <katja.marttila@qt.io> | 2022-03-18 13:01:00 +0200 |
commit | 0486535dc1e2cc8a902ee8625a822384e6c26e1e (patch) | |
tree | 0840714615d86f6709738b4e1655d3ee299e5bbb | |
parent | 1e676ad0eb6e1cf163b77923c7da9815b09e3def (diff) |
Do not uninstall needed virtual dependencies
Virtual dependencies are uninstalled if all dependencies to the
component is removed. Virtual dependencies were calculated using recent
components in repository, which is wrong as the dependencies may have
changed in the repository, causing the dependencies to be uninstalled
although those are still needed. Fixed so that the uninstallable virtual
components are calculated from repository components if the component is
going to be updated, otherwise the dependeny is calculated from the
local installed packages.
Task-number: QTIFW-2573
Change-Id: If9cc59fa7f453d502ec1883f27273ef604128a6e
Reviewed-by: Arttu Tarkiainen <arttu.tarkiainen@qt.io>
-rw-r--r-- | src/libs/installer/packagemanagercore.cpp | 43 | ||||
-rw-r--r-- | src/libs/installer/packagemanagercore.h | 3 | ||||
-rw-r--r-- | src/libs/installer/uninstallercalculator.cpp | 9 | ||||
-rw-r--r-- | src/libs/installer/uninstallercalculator.h | 2 |
4 files changed, 50 insertions, 7 deletions
diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp index d2c732ddb..820c97cb9 100644 --- a/src/libs/installer/packagemanagercore.cpp +++ b/src/libs/installer/packagemanagercore.cpp @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2021 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -2251,6 +2251,47 @@ QList<Component*> PackageManagerCore::dependees(const Component *_component) con } /*! + Returns a list of components that depend on \a component. The list can be + empty. Dependendants are calculated from components which are about to be updated, + if no update is requested then the dependant is calculated from installed packages. + + \note Automatic dependencies are not resolved. +*/ +QList<Component*> PackageManagerCore::installDependants(const Component *component) const +{ + if (!component) + return QList<Component *>(); + + const QList<QInstaller::Component *> availableComponents = components(ComponentType::All); + if (availableComponents.isEmpty()) + return QList<Component *>(); + + QList<Component *> dependants; + QString name; + QString version; + foreach (Component *availableComponent, availableComponents) { + if (isUpdater() && availableComponent->updateRequested()) { + const QStringList &dependencies = availableComponent->dependencies(); + foreach (const QString &dependency, dependencies) { + parseNameAndVersion(dependency, &name, &version); + if (componentMatches(component, name, version)) { + dependants.append(availableComponent); + } + } + } else { + KDUpdater::LocalPackage localPackage = d->m_localPackageHub->packageInfo(availableComponent->name()); + foreach (const QString &dependency, localPackage.dependencies) { + parseNameAndVersion(dependency, &name, &version); + if (componentMatches(component, name, version)) { + dependants.append(availableComponent); + } + } + } + } + return dependants; +} + +/*! Returns the default component model. */ ComponentModel *PackageManagerCore::defaultComponentModel() const diff --git a/src/libs/installer/packagemanagercore.h b/src/libs/installer/packagemanagercore.h index cf1916c48..012c57d58 100644 --- a/src/libs/installer/packagemanagercore.h +++ b/src/libs/installer/packagemanagercore.h @@ -1,6 +1,6 @@ /************************************************************************** ** -** Copyright (C) 2021 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the Qt Installer Framework. @@ -242,6 +242,7 @@ public: QString installReason(Component *component) const; QList<Component*> dependees(const Component *component) const; + QList<Component*> installDependants(const Component *component) const; ComponentModel *defaultComponentModel() const; ComponentModel *updaterComponentModel() const; diff --git a/src/libs/installer/uninstallercalculator.cpp b/src/libs/installer/uninstallercalculator.cpp index fc5620936..7d5ce9e2a 100644 --- a/src/libs/installer/uninstallercalculator.cpp +++ b/src/libs/installer/uninstallercalculator.cpp @@ -127,10 +127,10 @@ void UninstallerCalculator::appendComponentsToUninstall(const QList<Component*> if (!autoDependOnList.isEmpty()) appendComponentsToUninstall(autoDependOnList); else - continueAppendComponentsToUninstall(); + appendVirtualComponentsToUninstall(); } -void UninstallerCalculator::continueAppendComponentsToUninstall() +void UninstallerCalculator::appendVirtualComponentsToUninstall() { QList<Component*> unneededVirtualList; // Check for virtual components without dependees @@ -141,8 +141,9 @@ void UninstallerCalculator::continueAppendComponentsToUninstall() continue; bool required = false; - for (Component *dependee : m_core->dependees(component)) { - if (dependee->isInstalled() && !m_componentsToUninstall.contains(dependee)) { + // Check if installed or about to be updated -packages are dependant on the package + for (Component *dependant : m_core->installDependants(component)) { + if (dependant->isInstalled() && !m_componentsToUninstall.contains(dependant)) { required = true; break; } diff --git a/src/libs/installer/uninstallercalculator.h b/src/libs/installer/uninstallercalculator.h index 4d1f8816a..fb7035d4e 100644 --- a/src/libs/installer/uninstallercalculator.h +++ b/src/libs/installer/uninstallercalculator.h @@ -52,7 +52,7 @@ public: private: void appendComponentToUninstall(Component *component); - void continueAppendComponentsToUninstall(); + void appendVirtualComponentsToUninstall(); QList<Component *> m_installedComponents; QSet<Component *> m_componentsToUninstall; |