Allow disable of user plugins if repair command is requested

This commit is contained in:
Chris Roberts 2016-11-02 10:35:23 -07:00
parent 1fb4553d14
commit d5c5561302
2 changed files with 35 additions and 41 deletions

View File

@ -20,25 +20,17 @@ if argv.include?("-v") || argv.include?("--version")
exit 0 exit 0
end end
# This is kind of hacky, and I'd love to find a better way to do this, but # Disable plugin loading for commands where plugins are not required
# if we're accessing the plugin interface, we want to NOT load plugins
# for this run, because they can actually interfere with the function
# of the plugin interface.
argv.each_index do |i| argv.each_index do |i|
arg = argv[i] arg = argv[i]
if !arg.start_with?("-") if !arg.start_with?("-")
if arg == "plugin" if ["plugin", "help"].include?(arg) || (arg == "box" && argv[i+1] == "list")
ENV["VAGRANT_NO_PLUGINS"] = "1" ENV['VAGRANT_NO_PLUGINS'] = "1"
ENV["VAGRANT_VAGRANTFILE"] = "plugin_command_#{Time.now.to_i}"
end end
if arg == "help" if arg == "plugin" && argv[i+1] == "repair"
ENV["VAGRANT_VAGRANTFILE"] = "plugin_command_#{Time.now.to_i}" ENV['VAGRANT_DISABLE_PLUGIN_INIT'] = "1"
end
if arg == "box" && argv[i+1] == "list"
ENV["VAGRANT_VAGRANTFILE"] = "plugin_command_#{Time.now.to_i}"
end end
break break
@ -57,7 +49,7 @@ end
begin begin
require "bundler" require "bundler"
rescue Errno::EINVAL rescue Errno::EINVAL
# Bundler can generated the EINVAL error during initial require, which means # Bundler can generate the EINVAL error during initial require, which means
# nothing has yet been setup (so no access to I18n). Note that vagrant has # nothing has yet been setup (so no access to I18n). Note that vagrant has
# failed early and copy information related to problem and possible solution. # failed early and copy information related to problem and possible solution.
$stderr.puts "Vagrant failed to initialize at a very early stage:\n\n" $stderr.puts "Vagrant failed to initialize at a very early stage:\n\n"
@ -70,16 +62,17 @@ rescue Errno::EINVAL
exit 255 exit 255
end end
begin if(defined?(Bundler))
begin
$vagrant_bundler_runtime = Bundler.setup(:default, :plugins) $vagrant_bundler_runtime = Bundler.setup(:default, :plugins)
rescue Bundler::GemNotFound rescue Bundler::GemNotFound
$stderr.puts "Bundler, the underlying system used to manage Vagrant plugins," $stderr.puts "Bundler, the underlying system used to manage Vagrant plugins,"
$stderr.puts "is reporting that a plugin or its dependency can't be found." $stderr.puts "is reporting that a plugin or its dependency can't be found."
$stderr.puts "This is usually caused by manual tampering with the 'plugins.json'" $stderr.puts "This is usually caused by manual tampering with the 'plugins.json'"
$stderr.puts "file in the Vagrant home directory. To fix this error, please" $stderr.puts "file in the Vagrant home directory. To fix this error, please"
$stderr.puts "remove that file and reinstall all your plugins using `vagrant" $stderr.puts "remove that file and reinstall all your plugins using `vagrant"
$stderr.puts "plugin install`." $stderr.puts "plugin install`."
rescue Bundler::VersionConflict => e rescue Bundler::VersionConflict => e
$stderr.puts "Vagrant experienced a version conflict with some installed plugins!" $stderr.puts "Vagrant experienced a version conflict with some installed plugins!"
$stderr.puts "This usually happens if you recently upgraded Vagrant. As part of the" $stderr.puts "This usually happens if you recently upgraded Vagrant. As part of the"
$stderr.puts "upgrade process, some existing plugins are no longer compatible with" $stderr.puts "upgrade process, some existing plugins are no longer compatible with"
@ -96,6 +89,7 @@ rescue Bundler::VersionConflict => e
$stderr.puts "The error message is shown below:\n\n" $stderr.puts "The error message is shown below:\n\n"
$stderr.puts e.message $stderr.puts e.message
exit 1 exit 1
end
end end
# Stdout/stderr should not buffer output # Stdout/stderr should not buffer output

View File

@ -256,7 +256,7 @@ end
# Setup the plugin manager and load any defined plugins # Setup the plugin manager and load any defined plugins
require_relative "vagrant/plugin/manager" require_relative "vagrant/plugin/manager"
plugins = Vagrant::Plugin::Manager.instance.installed_plugins plugins = Vagrant::Plugin::Manager.instance.installed_plugins
Vagrant::Bundler.instance.init!(plugins) Vagrant::Bundler.instance.init!(plugins) unless ENV['VAGRANT_DISABLE_PLUGIN_INIT'] == "1"
# A lambda that knows how to load plugins from a single directory. # A lambda that knows how to load plugins from a single directory.
plugin_load_proc = lambda do |directory| plugin_load_proc = lambda do |directory|