From 1bba1f86bbec387a9297ffd0b705783805b959df Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 8 May 2018 13:46:44 -0700 Subject: [PATCH 1/3] Disable plugins on plugin commands but allow init when listing --- bin/vagrant | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/vagrant b/bin/vagrant index bac678f11..7720d0915 100755 --- a/bin/vagrant +++ b/bin/vagrant @@ -37,13 +37,18 @@ argv.each_index do |i| arg = argv[i] if !arg.start_with?("-") - if ["plugin", "help"].include?(arg) || (arg == "box" && argv[i+1] == "list") + if arg == "box" && argv[i+1] == "list" opts[:vagrantfile_name] = "" ENV['VAGRANT_NO_PLUGINS'] = "1" end - if arg == "plugin" && argv[i+1] != "list" - ENV['VAGRANT_DISABLE_PLUGIN_INIT'] = "1" + # Do not load plugins when performing plugin operations + if arg == "plugin" + ENV['VAGRANT_NO_PLUGINS'] = "1" + # Only initialize plugins when listing installed plugins + if argv[i+1] != "list" + ENV['VAGRANT_DISABLE_PLUGIN_INIT'] = "1" + end end break From d58096da314af58072c5c1b48c0f4237b1260d6b Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 8 May 2018 13:47:31 -0700 Subject: [PATCH 2/3] Update plugin loading to prevent error suppression Only catch exception types we care about when attempting to load plugins. If no require call is successful, force an exception instead of ignoring. --- lib/vagrant.rb | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/vagrant.rb b/lib/vagrant.rb index 4ecc33044..d980521c6 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -288,7 +288,7 @@ end if Vagrant.plugins_init? begin Vagrant::Bundler.instance.init!(plugins) - rescue Exception => e + rescue StandardError, ScriptError => e global_logger.error("Plugin initialization error - #{e.class}: #{e}") e.backtrace.each do |backtrace_line| global_logger.debug(backtrace_line) @@ -334,18 +334,16 @@ if Vagrant.plugins_enabled? plugins.each do |plugin_name, plugin_info| if plugin_info["require"].to_s.empty? begin - global_logger.debug("Loading plugin `#{plugin_name}` with default require: `#{plugin_name}`") + global_logger.info("Loading plugin `#{plugin_name}` with default require: `#{plugin_name}`") require plugin_name - rescue LoadError, Gem::LoadError => load_error + rescue LoadError => err if plugin_name.include?("-") - begin - plugin_slash = plugin_name.gsub("-", "/") - global_logger.debug("Failed to load plugin `#{plugin_name}` with default require.") - global_logger.debug("Loading plugin `#{plugin_name}` with slash require: `#{plugin_slash}`") - require plugin_slash - rescue LoadError, Gem::LoadError - global_logger.warn("Failed to load plugin `#{plugin_name}`. Assuming library and moving on.") - end + plugin_slash = plugin_name.gsub("-", "/") + global_logger.error("Failed to load plugin `#{plugin_name}` with default require. - #{err.class}: #{err}") + global_logger.info("Loading plugin `#{plugin_name}` with slash require: `#{plugin_slash}`") + require plugin_slash + else + raise end end else @@ -358,12 +356,12 @@ if Vagrant.plugins_enabled? global_logger.debug("Bundler detected in use. Loading `:plugins` group.") ::Bundler.require(:plugins) end - rescue Exception => e - global_logger.error("Plugin loading error: #{e.class} - #{e}") - e.backtrace.each do |backtrace_line| + rescue ScriptError, StandardError => err + global_logger.error("Plugin loading error: #{err.class} - #{err}") + err.backtrace.each do |backtrace_line| global_logger.debug(backtrace_line) end - raise Vagrant::Errors::PluginLoadError, message: e.to_s + raise Vagrant::Errors::PluginLoadError, message: err.to_s end else global_logger.debug("Plugin loading is currently disabled.") From 91018d4edca0ff3c2796f17443599bf59908450c Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 8 May 2018 13:52:23 -0700 Subject: [PATCH 3/3] Remove existing items from request set prior to installation --- lib/vagrant/bundler.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/vagrant/bundler.rb b/lib/vagrant/bundler.rb index aa76b889c..301e40e37 100644 --- a/lib/vagrant/bundler.rb +++ b/lib/vagrant/bundler.rb @@ -303,6 +303,15 @@ module Vagrant solution = request_set.resolve(installer_set) activate_solution(solution) + # Remove gems which are already installed + request_set.sorted_requests.delete_if do |activation_req| + rs_spec = activation_req.spec + if vagrant_internal_specs.detect{|ispec| ispec.name == rs_spec.name && ispec.version == rs_spec.version } + @logger.debug("Removing activation request from install. Already installed. (#{rs_spec.spec.full_name})") + true + end + end + @logger.debug("Installing required gems.") # Install all remote gems into plugin path. Set the installer to ignore dependencies