diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2021-08-02 12:06:43 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2021-08-19 15:46:40 +0900 |
commit | 679185d6c87e0f2e4f6a5da5ce50d02c80ab31b1 (patch) | |
tree | 293fa8c1f863aeb2f711310dc4941528fa829401 /lib/rubygems | |
parent | f1039afa4179f9d3a42f0d89b499e3c955b495d9 (diff) |
Merge RubyGems 3.2.24 and Bundler 2.2.24
Diffstat (limited to 'lib/rubygems')
-rw-r--r-- | lib/rubygems/gemcutter_utilities.rb | 3 | ||||
-rw-r--r-- | lib/rubygems/uninstaller.rb | 41 |
2 files changed, 38 insertions, 6 deletions
diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb index 00e68916c4..f465881041 100644 --- a/lib/rubygems/gemcutter_utilities.rb +++ b/lib/rubygems/gemcutter_utilities.rb @@ -31,7 +31,8 @@ module Gem::GemcutterUtilities def add_otp_option add_option('--otp CODE', - 'Digit code for multifactor authentication') do |value, options| + 'Digit code for multifactor authentication', + 'You can also use the environment variable GEM_HOST_OTP_CODE') do |value, options| options[:otp] = value end end diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb index 51ac3494f3..93e414b1c9 100644 --- a/lib/rubygems/uninstaller.rb +++ b/lib/rubygems/uninstaller.rb @@ -70,6 +70,9 @@ class Gem::Uninstaller # only add user directory if install_dir is not set @user_install = false @user_install = options[:user_install] unless options[:install_dir] + + # Optimization: populated during #uninstall + @default_specs_matching_uninstall_params = [] end ## @@ -98,10 +101,8 @@ class Gem::Uninstaller default_specs, list = list.partition do |spec| spec.default_gem? end - - default_specs.each do |default_spec| - say "Gem #{default_spec.full_name} cannot be uninstalled because it is a default gem" - end + warn_cannot_uninstall_default_gems(default_specs - list) + @default_specs_matching_uninstall_params = default_specs list, other_repo_specs = list.partition do |spec| @gem_home == spec.base_dir or @@ -270,7 +271,7 @@ class Gem::Uninstaller end safe_delete { FileUtils.rm_r gemspec } - say "Successfully uninstalled #{spec.full_name}" + announce_deletion_of(spec) Gem::Specification.reset end @@ -373,4 +374,34 @@ class Gem::Uninstaller raise e end + + private + + def announce_deletion_of(spec) + name = spec.full_name + say "Successfully uninstalled #{name}" + if default_spec_matches?(spec) + say( + "There was both a regular copy and a default copy of #{name}. The " \ + "regular copy was successfully uninstalled, but the default copy " \ + "was left around because default gems can't be removed." + ) + end + end + + # @return true if the specs of any default gems are `==` to the given `spec`. + def default_spec_matches?(spec) + !default_specs_that_match(spec).empty? + end + + # @return [Array] specs of default gems that are `==` to the given `spec`. + def default_specs_that_match(spec) + @default_specs_matching_uninstall_params.select {|default_spec| spec == default_spec } + end + + def warn_cannot_uninstall_default_gems(specs) + specs.each do |spec| + say "Gem #{spec.full_name} cannot be uninstalled because it is a default gem" + end + end end |