diff options
author | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2021-12-22 11:54:43 +0200 |
---|---|---|
committer | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2022-01-06 13:06:28 +0200 |
commit | c048aecb4858286a1516dba50317b4568f0d5c3d (patch) | |
tree | 9565c33387ca7cc6f665182ddbf22847288ffee0 /src/libs | |
parent | 46ce6b3127061b4645ef91fe0a63119337da4848 (diff) |
Do not replace conflicting remote packages silently with locals
On (tree)name conflicts with other than the same component in local and
remote packages - instead of silently replacing the remote package with
local, do one of the following:
- Remote package A may have declared the same tree name as installed
local package B. Catch the case and re-register package A as an
unstable component with the original name, if possible.
- Remote package A may have declared a tree name that conflicts with
local package B's name. Do not register component A.
Change-Id: I16ac583ea10bf203d8b8d0b19e6890f03cf0067a
Reviewed-by: Katja Marttila <katja.marttila@qt.io>
Diffstat (limited to 'src/libs')
-rw-r--r-- | src/libs/installer/packagemanagercore.cpp | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp index bb2eca6e6..81c0bea3a 100644 --- a/src/libs/installer/packagemanagercore.cpp +++ b/src/libs/installer/packagemanagercore.cpp @@ -3909,14 +3909,47 @@ bool PackageManagerCore::fetchAllPackages(const PackagesList &remotes, const Loc } else if (remoteTreeNameComponents.contains(localComponent->name())) { const QString remoteTreeName = remoteTreeNameComponents.value(localComponent->name()); const QString localTreeName = localComponent->value(scTreeName); - if (remoteTreeName != localTreeName) + if (remoteTreeName != localTreeName) { delete allComponents.take(remoteTreeNameComponents.value(localComponent->name())); - else + } else { + // 3. Component has same treename in local and remote, don't add the component again. continue; - // 3. Component has same treename in local and remote, don't add the component again. - } else if (allComponents.contains(name)) { - continue; + } + // 4. Component does not have treename in local or remote, don't add the component again. + } else if (allComponents.contains(localComponent->name())) { + Component *const component = allComponents.value(localComponent->name()); + if (component->value(scTreeName).isEmpty() && localComponent->value(scTreeName).isEmpty()) + continue; + } + // 5. Remote has treename for a different component that is already reserved + // by this local component, Or, remote adds component without treename + // but it conflicts with a local treename. + if (allComponents.contains(name)) { + const QString key = remoteTreeNameComponents.key(name); + qCritical() << "Cannot register component" << (key.isEmpty() ? name : key) + << "with name" << name << "! Component with identifier" << name + << "already exists."; + + if (!key.isEmpty()) + allTreeNameComponents.remove(key); + + // Try to re-add the remote component as unstable + if (!key.isEmpty() && !allComponents.contains(key) && settings().allowUnstableComponents()) { + qCDebug(lcInstallerInstallLog) + << "Registering component with the original indetifier:" << key; + + Component *component = allComponents.take(name); + component->removeValue(scTreeName); + const QString errorString = QLatin1String("Tree name conflicts with an existing indentifier"); + d->m_pendingUnstableComponents.insert(component->name(), + QPair<Component::UnstableError, QString>(Component::InvalidTreeName, errorString)); + + allComponents.insert(key, component); + } else { + delete allComponents.take(name); + } } + const QString treeName = localComponent->value(scTreeName); if (!treeName.isEmpty()) allTreeNameComponents.insert(localComponent->name(), treeName); |