From 572142df7ecce95e899b6998d6437055fd8e8ccd Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 3 Feb 2013 10:30:52 -0800 Subject: [PATCH] Perform gem uninstallation for prune --- plugins/commands/plugin/action/prune_gems.rb | 25 +++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/plugins/commands/plugin/action/prune_gems.rb b/plugins/commands/plugin/action/prune_gems.rb index e06511464..db9750baa 100644 --- a/plugins/commands/plugin/action/prune_gems.rb +++ b/plugins/commands/plugin/action/prune_gems.rb @@ -1,4 +1,5 @@ require "rubygems" +require "rubygems/uninstaller" require "set" require "log4r" @@ -121,7 +122,29 @@ module VagrantPlugins prune_specs = all_specs - good_specs @logger.info("Gems to prune: #{prune_specs.inspect}") - # TODO: Prune + if prune_specs.length > 0 + env[:gem_helper].with_environment do + prune_specs.each do |prune_spec| + uninstaller = Gem::Uninstaller.new(prune_spec.name, { + :executables => true, + :force => true, + :version => prune_spec.version.version + }) + + # This is sad, but there is no way to force this to be true + # so I just monkey-patch here. Vagrant has a pretty strict + # version check on the RubyGems version so this should be okay. + # In the future, let's try to get a pull request into RubyGems + # to fix this. + def uninstaller.ask_if_ok(spec) + true + end + + @logger.info("Uninstalling: #{prune_spec.name} (#{prune_spec.version})") + uninstaller.uninstall + end + end + end @app.call(env) end