core: better error if attempting to uninstall system plugin

This commit is contained in:
Mitchell Hashimoto 2014-03-03 15:05:32 -08:00
parent 5db58d6a33
commit 4437bcd77f
4 changed files with 52 additions and 0 deletions

View File

@ -488,6 +488,10 @@ module Vagrant
error_key(:plugin_state_file_not_parsable) error_key(:plugin_state_file_not_parsable)
end end
class PluginUninstallSystem < VagrantError
error_key(:plugin_uninstall_system)
end
class RSyncError < VagrantError class RSyncError < VagrantError
error_key(:rsync_error) error_key(:rsync_error)
end end

View File

@ -95,6 +95,13 @@ module Vagrant
# #
# @param [String] name # @param [String] name
def uninstall_plugin(name) def uninstall_plugin(name)
if @system_file
if !@user_file.has_plugin?(name) && @system_file.has_plugin?(name)
raise Errors::PluginUninstallSystem,
name: name
end
end
@user_file.remove_plugin(name) @user_file.remove_plugin(name)
# Clean the environment, removing any old plugins # Clean the environment, removing any old plugins

View File

@ -730,6 +730,14 @@ en:
Please remove the file and reinstall the plugins. Please remove the file and reinstall the plugins.
If this error recurs, please report a bug. If this error recurs, please report a bug.
plugin_uninstall_system: |-
The plugin you're attempting to uninstall ('%{name}') is a
system plugin. This means that the plugin is part of the installation
of Vagrant. These plugins cannot be removed.
You can however, install a plugin with the same name to replace
these plugins. User-installed plugins take priority over
system-installed plugins.
provider_not_found: |- provider_not_found: |-
The provider '%{provider}' could not be found, but was requested to The provider '%{provider}' could not be found, but was requested to
back the machine '%{machine}'. Please use a provider that exists. back the machine '%{machine}'. Please use a provider that exists.

View File

@ -149,6 +149,39 @@ describe Vagrant::Plugin::Manager do
expect { subject.uninstall_plugin("foo") }. expect { subject.uninstall_plugin("foo") }.
to raise_error(Vagrant::Errors::BundlerError) to raise_error(Vagrant::Errors::BundlerError)
end end
context "with a system file" do
let(:systems_path) { temporary_file }
before do
systems_path.unlink
described_class.stub(system_plugins_file: systems_path)
sf = Vagrant::Plugin::StateFile.new(systems_path)
sf.add_plugin("foo", version: "0.2.0")
sf.add_plugin("bar")
end
it "uninstalls the user plugin if it exists" do
sf = Vagrant::Plugin::StateFile.new(path)
sf.add_plugin("bar")
# Test
bundler.should_receive(:clean).once.with(anything)
# Remove it
subject.uninstall_plugin("bar")
plugins = subject.installed_plugins
expect(plugins["foo"]["system"]).to be_true
end
it "raises an error if uninstalling a system gem" do
expect { subject.uninstall_plugin("bar") }.
to raise_error(Vagrant::Errors::PluginUninstallSystem)
end
end
end end
describe "#update_plugins" do describe "#update_plugins" do