Adjustments to handle plugin updates using proper constraints

If a user provides the gem version using an explicit version or a
constraint, the update action should honor that constraint and not
simply replace it with an unbound constraint.

This also removes system plugin specifications from being matched
and preferred which prevents updates and can result in unexpected
downgrades when running the update.
This commit is contained in:
Chris Roberts 2017-06-27 17:17:13 -07:00
parent 97715280c2
commit 85d5f11f62
1 changed files with 18 additions and 5 deletions

View File

@ -220,7 +220,7 @@ module Vagrant
# Generate all required plugin deps # Generate all required plugin deps
plugin_deps = plugins.map do |name, info| plugin_deps = plugins.map do |name, info|
if update[:gems] == true || (update[:gems].respond_to?(:include?) && update[:gems].include?(name)) if update[:gems] == true || (update[:gems].respond_to?(:include?) && update[:gems].include?(name))
gem_version = '> 0' gem_version = plugins[name]["gem_version"].to_s.empty? ? "> 0" : plugins[name]["gem_version"]
skips << name skips << name
else else
gem_version = info['gem_version'].to_s.empty? ? '> 0' : info['gem_version'] gem_version = info['gem_version'].to_s.empty? ? '> 0' : info['gem_version']
@ -275,12 +275,16 @@ module Vagrant
# Create the request set for the new plugins # Create the request set for the new plugins
request_set = Gem::RequestSet.new(*plugin_deps) request_set = Gem::RequestSet.new(*plugin_deps)
system_plugins = plugins.map do |plugin_name, plugin_info|
plugin_name if plugin_info["system"]
end.compact
installer_set.system_plugins = system_plugins
installer_set = Gem::Resolver.compose_sets( installer_set = Gem::Resolver.compose_sets(
installer_set, installer_set,
generate_builtin_set, generate_builtin_set(system_plugins),
generate_plugin_set(skips) generate_plugin_set(skips)
) )
@logger.debug("Generating solution set for installation.") @logger.debug("Generating solution set for installation.")
# Generate the required solution set for new plugins # Generate the required solution set for new plugins
@ -349,11 +353,13 @@ module Vagrant
end end
# Generate the builtin resolver set # Generate the builtin resolver set
def generate_builtin_set def generate_builtin_set(system_plugins=[])
builtin_set = BuiltinSet.new builtin_set = BuiltinSet.new
@logger.debug("Generating new builtin set instance.") @logger.debug("Generating new builtin set instance.")
vagrant_internal_specs.each do |spec| vagrant_internal_specs.each do |spec|
builtin_set.add_builtin_spec(spec) if !system_plugins.include?(spec.name)
builtin_set.add_builtin_spec(spec)
end
end end
builtin_set builtin_set
end end
@ -428,9 +434,11 @@ module Vagrant
# the entire set used for performing full resolutions on install. # the entire set used for performing full resolutions on install.
class VagrantSet < Gem::Resolver::InstallerSet class VagrantSet < Gem::Resolver::InstallerSet
attr_accessor :prefer_sources attr_accessor :prefer_sources
attr_accessor :system_plugins
def initialize(domain, defined_sources={}) def initialize(domain, defined_sources={})
@prefer_sources = defined_sources @prefer_sources = defined_sources
@system_plugins = []
super(domain) super(domain)
end end
@ -438,6 +446,11 @@ module Vagrant
# for preferred sources # for preferred sources
def find_all(req) def find_all(req)
result = super result = super
if system_plugins.include?(req.name)
result.delete_if do |spec|
spec.is_a?(Gem::Resolver::InstalledSpecification)
end
end
subset = result.find_all do |idx_spec| subset = result.find_all do |idx_spec|
preferred = false preferred = false
if prefer_sources[req.name] if prefer_sources[req.name]