From 0486535dc1e2cc8a902ee8625a822384e6c26e1e Mon Sep 17 00:00:00 2001 From: Katja Marttila Date: Mon, 7 Mar 2022 17:40:01 +0200 Subject: 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 --- src/libs/installer/packagemanagercore.cpp | 43 +++++++++++++++++++++++++++- src/libs/installer/packagemanagercore.h | 3 +- src/libs/installer/uninstallercalculator.cpp | 9 +++--- src/libs/installer/uninstallercalculator.h | 2 +- 4 files changed, 50 insertions(+), 7 deletions(-) (limited to 'src/libs/installer') 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. @@ -2250,6 +2250,47 @@ QList PackageManagerCore::dependees(const Component *_component) con return dependees; } +/*! + 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 PackageManagerCore::installDependants(const Component *component) const +{ + if (!component) + return QList(); + + const QList availableComponents = components(ComponentType::All); + if (availableComponents.isEmpty()) + return QList(); + + QList 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. */ 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 dependees(const Component *component) const; + QList 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 if (!autoDependOnList.isEmpty()) appendComponentsToUninstall(autoDependOnList); else - continueAppendComponentsToUninstall(); + appendVirtualComponentsToUninstall(); } -void UninstallerCalculator::continueAppendComponentsToUninstall() +void UninstallerCalculator::appendVirtualComponentsToUninstall() { QList 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 m_installedComponents; QSet m_componentsToUninstall; -- cgit v1.2.3