2016-11-04 15:00:43 +00:00
|
|
|
require "vagrant/plugin/manager"
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module CommandPlugin
|
|
|
|
module Action
|
|
|
|
# This middleware removes user installed plugins by
|
|
|
|
# removing:
|
|
|
|
# * ~/.vagrant.d/plugins.json
|
|
|
|
# * ~/.vagrant.d/gems
|
|
|
|
# Usage should be restricted to when a repair is
|
|
|
|
# unsuccessful and the only reasonable option remaining
|
|
|
|
# is to re-install all plugins
|
|
|
|
class ExpungePlugins
|
|
|
|
def initialize(app, env)
|
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
if !env[:force]
|
2017-01-12 15:16:57 +00:00
|
|
|
|
|
|
|
result = nil
|
|
|
|
attempts = 0
|
|
|
|
while attempts < 5 && result.nil?
|
|
|
|
attempts += 1
|
|
|
|
result = env[:ui].ask(
|
|
|
|
I18n.t("vagrant.commands.plugin.expunge_confirm") +
|
|
|
|
" [N]: "
|
|
|
|
)
|
|
|
|
result = result.to_s.downcase.strip
|
|
|
|
result = "n" if result.empty?
|
|
|
|
if !["y", "yes", "n", "no"].include?(result)
|
|
|
|
result = nil
|
|
|
|
env[:ui].error("Please answer Y or N")
|
|
|
|
else
|
|
|
|
result = result[0,1]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if result != 'y'
|
2016-11-08 03:25:32 +00:00
|
|
|
abort_action = true
|
2016-11-04 15:00:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-08 03:25:32 +00:00
|
|
|
if !abort_action
|
2018-05-10 19:03:21 +00:00
|
|
|
files = []
|
|
|
|
dirs = []
|
2016-11-04 15:00:43 +00:00
|
|
|
|
2018-05-10 19:03:21 +00:00
|
|
|
# Do not include global paths if local only
|
2018-07-18 20:43:52 +00:00
|
|
|
if !env[:env_local_only] || env[:global_only]
|
2018-07-17 22:16:38 +00:00
|
|
|
files << Vagrant::Plugin::Manager.instance.user_file.path
|
2018-05-10 19:03:21 +00:00
|
|
|
dirs << Vagrant::Bundler.instance.plugin_gem_path
|
2016-11-08 03:25:32 +00:00
|
|
|
end
|
2016-11-04 15:00:43 +00:00
|
|
|
|
2018-05-10 19:03:21 +00:00
|
|
|
# Add local paths if they exist
|
2018-07-18 20:43:52 +00:00
|
|
|
if Vagrant::Plugin::Manager.instance.local_file && (env[:env_local_only] || !env[:global_only])
|
2018-07-17 22:16:38 +00:00
|
|
|
files << Vagrant::Plugin::Manager.instance.local_file.path
|
2018-05-10 19:03:21 +00:00
|
|
|
dirs << Vagrant::Bundler.instance.env_plugin_gem_path
|
2016-11-08 03:25:32 +00:00
|
|
|
end
|
2016-11-04 15:00:43 +00:00
|
|
|
|
2018-05-10 19:03:21 +00:00
|
|
|
# Expunge files and directories
|
|
|
|
files.find_all(&:exist?).map(&:delete)
|
|
|
|
dirs.find_all(&:exist?).map(&:rmtree)
|
|
|
|
|
2016-11-08 03:25:32 +00:00
|
|
|
env[:ui].info(I18n.t("vagrant.commands.plugin.expunge_complete"))
|
2016-11-04 15:00:43 +00:00
|
|
|
|
2016-11-08 03:25:32 +00:00
|
|
|
@app.call(env)
|
|
|
|
else
|
|
|
|
env[:ui].info(I18n.t("vagrant.commands.plugin.expunge_aborted"))
|
|
|
|
end
|
2016-11-04 15:00:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|