aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems/commands/cleanup_command.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-09 21:38:59 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-06-09 21:38:59 +0000
commit31c94ffeb5f09d09ac2c86fc9e6614e38251a43d (patch)
tree10e44506238c7af3d7c9d822111996731726e38d /lib/rubygems/commands/cleanup_command.rb
parenta6afbaeb3be396c0fdea3b9077d9256c59edcfca (diff)
downloadruby-31c94ffeb5f09d09ac2c86fc9e6614e38251a43d.tar.gz
Update to RubyGems 1.3.4 r2223
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/commands/cleanup_command.rb')
-rw-r--r--lib/rubygems/commands/cleanup_command.rb27
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/rubygems/commands/cleanup_command.rb b/lib/rubygems/commands/cleanup_command.rb
index 40dcb9db34..1b6e405782 100644
--- a/lib/rubygems/commands/cleanup_command.rb
+++ b/lib/rubygems/commands/cleanup_command.rb
@@ -1,6 +1,7 @@
require 'rubygems/command'
require 'rubygems/source_index'
require 'rubygems/dependency_list'
+require 'rubygems/uninstaller'
class Gem::Commands::CleanupCommand < Gem::Command
@@ -22,6 +23,13 @@ class Gem::Commands::CleanupCommand < Gem::Command
"--no-dryrun"
end
+ def description # :nodoc:
+ <<-EOF
+The cleanup command removes old gems from GEM_HOME. If an older version is
+installed elsewhere in GEM_PATH the cleanup command won't touch it.
+ EOF
+ end
+
def usage # :nodoc:
"#{program_name} [GEMNAME ...]"
end
@@ -41,7 +49,8 @@ class Gem::Commands::CleanupCommand < Gem::Command
unless options[:args].empty? then
options[:args].each do |gem_name|
- specs = Gem.cache.search(/^#{gem_name}$/i)
+ dep = Gem::Dependency.new gem_name, Gem::Requirement.default
+ specs = Gem.source_index.search dep
specs.each do |spec|
gems_to_cleanup << spec
end
@@ -56,7 +65,6 @@ class Gem::Commands::CleanupCommand < Gem::Command
primary_gems[spec.name].version != spec.version
}
- uninstall_command = Gem::CommandManager.instance['uninstall']
deplist = Gem::DependencyList.new
gems_to_cleanup.uniq.each do |spec| deplist.add spec end
@@ -69,14 +77,21 @@ class Gem::Commands::CleanupCommand < Gem::Command
say "Attempting to uninstall #{spec.full_name}"
options[:args] = [spec.name]
- options[:version] = "= #{spec.version}"
- options[:executables] = false
- uninstaller = Gem::Uninstaller.new spec.name, options
+ uninstall_options = {
+ :executables => false,
+ :version => "= #{spec.version}",
+ }
+
+ if Gem.user_dir == spec.installation_path then
+ uninstall_options[:install_dir] = spec.installation_path
+ end
+
+ uninstaller = Gem::Uninstaller.new spec.name, uninstall_options
begin
uninstaller.uninstall
- rescue Gem::DependencyRemovalException,
+ rescue Gem::DependencyRemovalException, Gem::InstallError,
Gem::GemNotInHomeException => e
say "Unable to uninstall #{spec.full_name}:"
say "\t#{e.class}: #{e.message}"