Fix dependency resolution in mod upgrades #3200
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Upgrading mods that previously provided a module and depend on it in the next version currently fails:
In this case, Kopernicus-BE v1.10.1-45 provided ModularFlightIntegrator, but Kopernicus-BE v1.10.1-46 no longer does so and has it as dependency instead (see #3193). CKAN should automatically pull in MFI to satisfy the new dependency.
Causes
ModuleInstaller.Upgrade(IEnumerable<string> identifiers, ...)
doesn't tell the newly createdRelationshipResolver
that it also removes the old modules before adding the new ones. So the dependency is wrongly satisfied by the old module.RelationshipResolver(IEnumerable<string> modulesToInstall, IEnumerable<string> modulesToRemove, ...)
tries to find matchingCkanModule
s for all the identifiers inmodulesToInstall
andmodulesToRemove
. It does so by callingTranslateModule()
->FromIDandVersion()
, that ultimately returns the latest compatible module.This is fine for
modulesToInstall
, however formodulesToRemove
we only want search through the currently installed modules (we can only remove modules that are actually installed after all).RelationshipResolver.ResolveStanza()
checks whether dependencies of the new modules are already satisfied by the installed modules, however it does so by querying the registry, which might have outdated information. Thus it incorrectly assumes the dependencies are satisfied (by the old mod versions). Only the resolvers owninstalled_modules
knows about the modules that are going to be removed.Changes
ModuleInstaller.Upgrade()
now tells the relationship resolver which modules it's about remove by passing the same identifier list formodulesToRemove
as it passes formodulesToInstall
.RelationshipResolver()
now usesregistry.InstalledModule()
to convert identifiers toCkanModule
s formodulesToRemove
. We can use the registry here since we're just in the process of creating the resolver andinstalled_modules
is only declared and populated a few steps later.RelationshipResolver.ResolveStanza()
now looks into the resolvers owninstalled_modules
instead of querying the potentially outdated registry.installed_modules
is already reduced by the modules that are about to be removed, thus the resolver has to find other mods that can satisfy the .dependencies