[rubygems/rubygems] Fix gem uninstall warning when two versions of psych installed

https://github.com/rubygems/rubygems/commit/1b5644b666
This commit is contained in:
David Rodriguez 2024-05-16 16:32:56 +02:00 committed by git
parent 78ccf770aa
commit 8e2a6435e4
4 changed files with 34 additions and 14 deletions

View File

@ -210,4 +210,25 @@ class Gem::StubSpecification < Gem::BasicSpecification
def stubbed?
data.is_a? StubLine
end
def ==(other) # :nodoc:
self.class === other &&
name == other.name &&
version == other.version &&
platform == other.platform
end
alias_method :eql?, :== # :nodoc:
def hash # :nodoc:
name.hash ^ version.hash ^ platform.hash
end
def <=>(other) # :nodoc:
sort_obj <=> other.sort_obj
end
def sort_obj # :nodoc:
[name, version, Gem::Platform.sort_priority(platform)]
end
end

View File

@ -86,11 +86,7 @@ class Gem::Uninstaller
list = []
dirs =
Gem::Specification.dirs +
[Gem.default_specifications_dir]
Gem::Specification.each_spec dirs do |spec|
specification_record.stubs.each do |spec|
next unless dependency.matches_spec? spec
list << spec
@ -102,7 +98,7 @@ class Gem::Uninstaller
default_specs, list = list.partition(&:default_gem?)
warn_cannot_uninstall_default_gems(default_specs - list)
@default_specs_matching_uninstall_params = default_specs
@default_specs_matching_uninstall_params = default_specs.map(&:to_spec)
list, other_repo_specs = list.partition do |spec|
@gem_home == spec.base_dir ||
@ -126,7 +122,7 @@ class Gem::Uninstaller
remove_all list
elsif list.size > 1
gem_names = list.map(&:full_name)
gem_names = list.map(&:full_name_with_location)
gem_names << "All versions"
say
@ -147,7 +143,9 @@ class Gem::Uninstaller
##
# Uninstalls gem +spec+
def uninstall_gem(spec)
def uninstall_gem(stub)
spec = stub.to_spec
@spec = spec
unless dependencies_ok? spec
@ -165,6 +163,8 @@ class Gem::Uninstaller
remove_plugins @spec
remove @spec
specification_record.remove_spec(stub)
regenerate_plugins
Gem.post_uninstall_hooks.each do |hook|
@ -275,8 +275,6 @@ class Gem::Uninstaller
safe_delete { FileUtils.rm_r gemspec }
announce_deletion_of(spec)
Gem::Specification.reset
end
##
@ -292,7 +290,6 @@ class Gem::Uninstaller
# Regenerates plugin wrappers after removal.
def regenerate_plugins
specification_record = @install_dir ? Gem::SpecificationRecord.from_path(@install_dir) : Gem::Specification.specification_record
latest = specification_record.latest_spec_for(@spec.name)
return if latest.nil?
@ -381,6 +378,10 @@ class Gem::Uninstaller
private
def specification_record
@specification_record ||= @install_dir ? Gem::SpecificationRecord.from_path(@install_dir) : Gem::Specification.specification_record
end
def announce_deletion_of(spec)
name = spec.full_name
say "Successfully uninstalled #{name}"

View File

@ -32,7 +32,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase
@cmd.execute
end
assert_equal %w[a_evil-9 b-2 c-1.2 default-1 dep_x-1 pl-1-x86-linux x-1],
assert_equal %w[a-4 a_evil-9 b-2 c-1.2 default-1 dep_x-1 pl-1-x86-linux x-1],
Gem::Specification.all_names.sort
end

View File

@ -19,8 +19,6 @@ class TestGemUninstaller < Gem::InstallerTestCase
@user_spec = @user_installer.spec
end
end
Gem::Specification.reset
end
def test_initialize_expand_path