From 21de5f081ab3b18625febcd8ac181f6a122c4c7f Mon Sep 17 00:00:00 2001 From: Katja Marttila Date: Tue, 3 May 2022 11:59:21 +0300 Subject: Do not install new dependencies for installed components If component is updated to repository, and new dependencies are added, the dependencies should be installed only when fresh install to component is made or the component is updated. This change adds a new LocalDependencies value to component. It keeps track of the dependencies the local installed packages has. Fixes also a bug in uninstallecalculator, where we should also read the dependencies from local installed packages instead of newly introduced repositories. Task-number: QTIFW-2624 Change-Id: I0557e5adf1e87c0a1238cc455cfb2c90f6b05c87 Reviewed-by: Arttu Tarkiainen --- src/libs/installer/component.cpp | 35 +++++++++++++++++++++++++++- src/libs/installer/component.h | 4 +++- src/libs/installer/constants.h | 1 + src/libs/installer/installercalculator.cpp | 4 ++-- src/libs/installer/packagemanagercore.cpp | 2 ++ src/libs/installer/packagemanagercore_p.cpp | 10 ++++---- src/libs/installer/packagemanagercore_p.h | 2 +- src/libs/installer/qinstallerglobal.h | 2 +- src/libs/installer/uninstallercalculator.cpp | 8 +++---- src/libs/installer/uninstallercalculator.h | 4 ++-- 10 files changed, 55 insertions(+), 17 deletions(-) (limited to 'src/libs') diff --git a/src/libs/installer/component.cpp b/src/libs/installer/component.cpp index 702dd2763..c703bfdcd 100644 --- a/src/libs/installer/component.cpp +++ b/src/libs/installer/component.cpp @@ -308,6 +308,10 @@ void Component::loadDataFromPackage(const KDUpdater::LocalPackage &package) setValue(scTreeName, package.treeName.first); d->m_treeNameMoveChildren = package.treeName.second; + + // scDependencies might be updated from repository later, + // keep the local dependencies as well. + setValue(scLocalDependencies, value(scDependencies)); } /*! @@ -1354,11 +1358,22 @@ void Component::addDependency(const QString &newDependency) setValue(scDependencies, oldDependencies + QLatin1String(", ") + newDependency); } +/*! + Returns a list of dependencies defined in the the repository or in the package.xml. +*/ QStringList Component::dependencies() const { return d->m_vars.value(scDependencies).split(QInstaller::commaRegExp(), Qt::SkipEmptyParts); } +/*! + Returns a list of installed components dependencies defined in the components.xml. +*/ +QStringList Component::localDependencies() const +{ + return d->m_vars.value(scLocalDependencies).split(QInstaller::commaRegExp(), Qt::SkipEmptyParts); +} + /*! Adds the component specified by \a newDependOn to the automatic depend-on list. Alternatively, multiple components can be specified by separating each with @@ -1382,6 +1397,24 @@ QStringList Component::autoDependencies() const return d->m_vars.value(scAutoDependOn).split(QInstaller::commaRegExp(), Qt::SkipEmptyParts); } +/*! + Returns a list of dependencies that the component currently has. The + dependencies can vary when component is already installed with different + dependency list than what is introduced in the repository. If component is + not installed, or update is requested to an installed component, + current dependencies are read from repository so that correct dependencies + are calculated for the component when it is installed or updated. +*/ +QStringList Component::currentDependencies() const +{ + QStringList dependenciesList; + if (isInstalled() && !updateRequested()) + dependenciesList = localDependencies(); + else + dependenciesList = dependencies(); + return dependenciesList; +} + /*! \sa {component::setInstalled}{component.setInstalled} */ @@ -1519,7 +1552,7 @@ bool Component::isUpdateAvailable() const \sa {component::updateRequested}{component.updateRequested} */ -bool Component::updateRequested() +bool Component::updateRequested() const { return d->m_updateIsAvailable && isSelected() && !isUnstable(); } diff --git a/src/libs/installer/component.h b/src/libs/installer/component.h index dbf604a56..e5f1b38da 100644 --- a/src/libs/installer/component.h +++ b/src/libs/installer/component.h @@ -170,8 +170,10 @@ public: Q_INVOKABLE void addDependency(const QString &newDependency); QStringList dependencies() const; + QStringList localDependencies() const; Q_INVOKABLE void addAutoDependOn(const QString &newDependOn); QStringList autoDependencies() const; + QStringList currentDependencies() const; void languageChanged(); QString localTempPath() const; @@ -195,7 +197,7 @@ public: Q_INVOKABLE void setUpdateAvailable(bool isUpdateAvailable); Q_INVOKABLE bool isUpdateAvailable() const; - Q_INVOKABLE bool updateRequested(); + Q_INVOKABLE bool updateRequested() const; Q_INVOKABLE bool componentChangeRequested(); Q_INVOKABLE bool isForcedUpdate(); diff --git a/src/libs/installer/constants.h b/src/libs/installer/constants.h index af518a0f6..7fa54c4ec 100644 --- a/src/libs/installer/constants.h +++ b/src/libs/installer/constants.h @@ -59,6 +59,7 @@ static const QLatin1String scDisplayName("DisplayName"); static const QLatin1String scTreeName("TreeName"); static const QLatin1String scAutoTreeName("AutoTreeName"); static const QLatin1String scDependencies("Dependencies"); +static const QLatin1String scLocalDependencies("LocalDependencies"); static const QLatin1String scAutoDependOn("AutoDependOn"); static const QLatin1String scNewComponent("NewComponent"); static const QLatin1String scRepositories("Repositories"); diff --git a/src/libs/installer/installercalculator.cpp b/src/libs/installer/installercalculator.cpp index 21e82fc9a..2ef5d3b74 100644 --- a/src/libs/installer/installercalculator.cpp +++ b/src/libs/installer/installercalculator.cpp @@ -109,7 +109,7 @@ bool InstallerCalculator::appendComponentsToInstall(const QList &co } } - if (component->dependencies().isEmpty()) + if (component->currentDependencies().isEmpty()) realAppendToInstallComponents(component, QString(), revertFromInstall); else notAppendedComponents.append(component); @@ -177,7 +177,7 @@ void InstallerCalculator::realAppendToInstallComponents(Component *component, co bool InstallerCalculator::appendComponentToInstall(Component *component, const QString &version, bool revertFromInstall) { - const QStringList dependenciesList = component->dependencies(); + const QStringList dependenciesList = component->currentDependencies(); QSet allDependencies(dependenciesList.begin(), dependenciesList.end()); QString requiredDependencyVersion = version; foreach (const QString &dependencyComponentName, allDependencies) { diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp index 8ebaefd62..543852e20 100644 --- a/src/libs/installer/packagemanagercore.cpp +++ b/src/libs/installer/packagemanagercore.cpp @@ -3922,6 +3922,8 @@ bool PackageManagerCore::updateComponentData(struct Data &data, Component *compo // a possible component to replace that might be installed (to mark the replacement as installed). component->setInstalled(); component->setValue(scInstalledVersion, data.installedPackages->value(name).version); + component->setValue(scLocalDependencies, data.installedPackages->value(name). + dependencies.join(QLatin1String(","))); return true; } diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp index 85e902ac3..e279a8027 100644 --- a/src/libs/installer/packagemanagercore_p.cpp +++ b/src/libs/installer/packagemanagercore_p.cpp @@ -463,7 +463,7 @@ void PackageManagerCorePrivate::cleanUpComponentEnvironment() { m_componentReplaces.clear(); m_autoDependencyComponentHash.clear(); - m_dependencyComponentHash.clear(); + m_localDependencyComponentHash.clear(); m_localVirtualComponents.clear(); // clean up registered (downloaded) data if (m_core->isMaintainer()) @@ -596,7 +596,7 @@ UninstallerCalculator *PackageManagerCorePrivate::uninstallerCalculator() const } pmcp->m_uninstallerCalculator = new UninstallerCalculator(installedComponents, m_core, - pmcp->m_autoDependencyComponentHash, pmcp->m_dependencyComponentHash, pmcp->m_localVirtualComponents); + pmcp->m_autoDependencyComponentHash, pmcp->m_localDependencyComponentHash, pmcp->m_localVirtualComponents); } return m_uninstallerCalculator; } @@ -3164,11 +3164,11 @@ void PackageManagerCorePrivate::createDependencyHashes(const Component* componen m_autoDependencyComponentHash.insert(autodepend, value); } - for (const QString &depend : component->dependencies()) { - QStringList value = m_dependencyComponentHash.value(depend); + for (const QString &depend : component->localDependencies()) { + QStringList value = m_localDependencyComponentHash.value(depend); if (!value.contains(component->name())) value.append(component->name()); - m_dependencyComponentHash.insert(depend, value); + m_localDependencyComponentHash.insert(depend, value); } } diff --git a/src/libs/installer/packagemanagercore_p.h b/src/libs/installer/packagemanagercore_p.h index 3a859f63d..8a5b805d8 100644 --- a/src/libs/installer/packagemanagercore_p.h +++ b/src/libs/installer/packagemanagercore_p.h @@ -311,7 +311,7 @@ private: QHash m_coreCheckedHash; QList m_deletedReplacedComponents; AutoDependencyHash m_autoDependencyComponentHash; - DependencyHash m_dependencyComponentHash; + LocalDependencyHash m_localDependencyComponentHash; QStringList m_localVirtualComponents; diff --git a/src/libs/installer/qinstallerglobal.h b/src/libs/installer/qinstallerglobal.h index 5bc87e21d..88f255af6 100644 --- a/src/libs/installer/qinstallerglobal.h +++ b/src/libs/installer/qinstallerglobal.h @@ -58,7 +58,7 @@ typedef QList PackagesList; typedef QMap LocalPackagesMap; typedef QHash AutoDependencyHash; -typedef QHash DependencyHash; +typedef QHash LocalDependencyHash; } // namespace QInstaller diff --git a/src/libs/installer/uninstallercalculator.cpp b/src/libs/installer/uninstallercalculator.cpp index c717f6550..af03df8c5 100644 --- a/src/libs/installer/uninstallercalculator.cpp +++ b/src/libs/installer/uninstallercalculator.cpp @@ -45,12 +45,12 @@ namespace QInstaller { UninstallerCalculator::UninstallerCalculator(const QList &installedComponents , PackageManagerCore *core , const AutoDependencyHash &autoDependencyComponentHash - , const DependencyHash &dependencyComponentHash + , const LocalDependencyHash &localDependencyComponentHash , const QStringList &localVirtualComponents) : m_installedComponents(installedComponents) , m_core(core) , m_autoDependencyComponentHash(autoDependencyComponentHash) - , m_dependencyComponentHash(dependencyComponentHash) + , m_localDependencyComponentHash(localDependencyComponentHash) , m_localVirtualComponents(localVirtualComponents) { } @@ -68,8 +68,8 @@ void UninstallerCalculator::appendComponentToUninstall(Component *component, con if (!component->isInstalled()) return; - if (m_dependencyComponentHash.contains(component->name())) { - const QStringList &dependencies = PackageManagerCore::parseNames(m_dependencyComponentHash.value(component->name())); + if (m_localDependencyComponentHash.contains(component->name())) { + const QStringList &dependencies = PackageManagerCore::parseNames(m_localDependencyComponentHash.value(component->name())); for (const QString &dependencyComponent : dependencies) { Component *depComponent = m_core->componentByName(dependencyComponent); if (depComponent && depComponent->isInstalled() && !m_componentsToUninstall.contains(depComponent)) { diff --git a/src/libs/installer/uninstallercalculator.h b/src/libs/installer/uninstallercalculator.h index a458daa80..76e32c6a6 100644 --- a/src/libs/installer/uninstallercalculator.h +++ b/src/libs/installer/uninstallercalculator.h @@ -55,7 +55,7 @@ public: UninstallerCalculator(const QList &installedComponents, PackageManagerCore *core, const AutoDependencyHash &autoDependencyComponentHash, - const DependencyHash &dependencyComponentHash, + const LocalDependencyHash &localDependencyComponentHash, const QStringList &localVirtualComponents); QSet componentsToUninstall() const; @@ -78,7 +78,7 @@ private: PackageManagerCore *m_core; QHash > m_toUninstallComponentIdReasonHash; AutoDependencyHash m_autoDependencyComponentHash; - DependencyHash m_dependencyComponentHash; + LocalDependencyHash m_localDependencyComponentHash; QStringList m_localVirtualComponents; QList m_virtualComponentsForReverse; }; -- cgit v1.2.3