diff options
-rw-r--r-- | lib/rubygems/uninstaller.rb | 60 |
1 files changed, 40 insertions, 20 deletions
@@ -12,6 +12,11 @@ require 'rubygems/user_interaction' ## # An Uninstaller. class Gem::Uninstaller @@ -46,8 +51,17 @@ class Gem::Uninstaller @force_ignore = options[:ignore] @bin_dir = options[:bin_dir] spec_dir = File.join @gem_home, 'specifications' @source_index = Gem::SourceIndex.from_gems_in spec_dir end ## @@ -56,9 +70,10 @@ class Gem::Uninstaller def uninstall list = @source_index.find_name @gem, @version if list.empty? then - raise Gem::InstallError, "Unknown gem #{@gem} #{@version}" elsif list.size > 1 and @force_all then remove_all list.dup @@ -91,8 +106,8 @@ class Gem::Uninstaller hook.call self end - specs.each { |s| remove_executables s } - remove spec, specs Gem.post_uninstall_hooks.each do |hook| hook.call self @@ -105,29 +120,29 @@ class Gem::Uninstaller # Removes installed executables and batch files (windows only) for # +gemspec+. - def remove_executables(gemspec) - return if gemspec.nil? - if gemspec.executables.size > 0 then - bindir = @bin_dir ? @bin_dir : (Gem.bindir @gem_home) - list = @source_index.find_name(gemspec.name).delete_if { |spec| - spec.version == gemspec.version } - executables = gemspec.executables.clone - list.each do |spec| - spec.executables.each do |exe_name| - executables.delete(exe_name) end end - return if executables.size == 0 answer = if @force_executables.nil? then ask_yes_no("Remove executables:\n" \ - "\t#{gemspec.executables.join(", ")}\n\nin addition to the gem?", true) # " # appease ruby-mode - don't ask else @force_executables @@ -138,7 +153,7 @@ class Gem::Uninstaller else raise Gem::FilePermissionError, bindir unless File.writable? bindir - gemspec.executables.each do |exe_name| say "Removing #{exe_name}" FileUtils.rm_f File.join(bindir, exe_name) FileUtils.rm_f File.join(bindir, "#{exe_name}.bat") @@ -169,7 +184,8 @@ class Gem::Uninstaller "Uninstallation aborted due to dependent gem(s)" end - unless path_ok? spec then e = Gem::GemNotInHomeException.new \ "Gem is not installed in directory #{@gem_home}" e.spec = spec @@ -210,9 +226,12 @@ class Gem::Uninstaller list.delete spec end - def path_ok?(spec) - full_path = File.join @gem_home, 'gems', spec.full_name - original_path = File.join @gem_home, 'gems', spec.original_name full_path == spec.full_gem_path || original_path == spec.full_gem_path end @@ -221,6 +240,7 @@ class Gem::Uninstaller return true if @force_ignore deplist = Gem::DependencyList.from_source_index @source_index deplist.ok_to_remove?(spec.full_name) || ask_if_ok(spec) end |