From 8cc45aae947d453acca029e13eb64f3f5f0bf942 Mon Sep 17 00:00:00 2001 From: drbrain Date: Mon, 31 Mar 2008 22:40:06 +0000 Subject: Import RubyGems 1.1.0 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems/uninstaller.rb | 60 +++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 29 deletions(-) (limited to 'lib/rubygems/uninstaller.rb') diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb index 1c979d8573..e2b5e5372b 100644 --- a/lib/rubygems/uninstaller.rb +++ b/lib/rubygems/uninstaller.rb @@ -12,7 +12,7 @@ require 'rubygems/user_interaction' ## # An Uninstaller. -# + class Gem::Uninstaller include Gem::UserInteraction @@ -21,8 +21,8 @@ class Gem::Uninstaller # Constructs an Uninstaller instance # # gem:: [String] The Gem name to uninstall - # - def initialize(gem, options) + + def initialize(gem, options = {}) @gem = gem @version = options[:version] || Gem::Requirement.default gem_home = options[:install_dir] || Gem.dir @@ -30,12 +30,13 @@ class Gem::Uninstaller @force_executables = options[:executables] @force_all = options[:all] @force_ignore = options[:ignore] + @bin_dir = options[:bin_dir] end ## # Performs the uninstall of the Gem. This removes the spec, the # Gem directory, and the cached .gem file, - # + def uninstall list = Gem.source_index.search(/^#{@gem}$/, @version) @@ -66,18 +67,14 @@ class Gem::Uninstaller end ## - # Remove executables and batch files (windows only) for the gem as - # it is being installed - # - # gemspec::[Specification] the gem whose executables need to be removed. - # + # 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 = Gem.bindir @gem_home - - raise Gem::FilePermissionError, bindir unless File.writable? bindir + bindir = @bin_dir ? @bin_dir : (Gem.bindir @gem_home) list = Gem.source_index.search(gemspec.name).delete_if { |spec| spec.version == gemspec.version @@ -93,14 +90,19 @@ class Gem::Uninstaller return if executables.size == 0 - answer = @force_executables || ask_yes_no( - "Remove executables:\n" \ - "\t#{gemspec.executables.join(", ")}\n\nin addition to the gem?", - true) # " # appease ruby-mode - don't ask + 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 + end unless answer then say "Executables and scripts will remain installed." 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) @@ -110,23 +112,22 @@ class Gem::Uninstaller end end + ## + # Removes all gems in +list+. # - # list:: the list of all gems to remove - # - # Warning: this method modifies the +list+ parameter. Once it has - # uninstalled a gem, it is removed from that list. - # + # NOTE: removes uninstalled gems from +list+. + def remove_all(list) - list.dup.each { |gem| remove(gem, list) } + list.dup.each { |spec| remove spec, list } end - # + ## # spec:: the spec of the gem to be uninstalled # list:: the list of all such gems # # Warning: this method modifies the +list+ parameter. Once it has # uninstalled a gem, it is removed from that list. - # + def remove(spec, list) unless dependencies_ok? spec then raise Gem::DependencyRemovalException, @@ -134,10 +135,11 @@ class Gem::Uninstaller end unless path_ok? spec then - alert("In order to remove #{spec.name}, please execute:\n" \ - "\tgem uninstall #{spec.name} --install-dir=#{spec.installation_path}") - raise Gem::GemNotInHomeException, + e = Gem::GemNotInHomeException.new \ "Gem is not installed in directory #{@gem_home}" + e.spec = spec + + raise e end raise Gem::FilePermissionError, spec.installation_path unless @@ -182,8 +184,8 @@ class Gem::Uninstaller def dependencies_ok?(spec) return true if @force_ignore - srcindex = Gem::SourceIndex.from_installed_gems - deplist = Gem::DependencyList.from_source_index srcindex + source_index = Gem::SourceIndex.from_installed_gems + deplist = Gem::DependencyList.from_source_index source_index deplist.ok_to_remove?(spec.full_name) || ask_if_ok(spec) end -- cgit v1.2.1