[rubygems/rubygems] Use spec.base_dir to remove plugins

The plugin loader from `@gem_home` was removed during uninstallation.
However, this could leave behind the plugins for `--user-install`
installed gems.

Use `Gem::Specifictaions#base_dir` instead. This ensures that the plugin
loader for associated .gemspec is uninstalled.

https://github.com/rubygems/rubygems/commit/6047f78210
This commit is contained in:
Vít Ondruch 2023-03-13 14:32:19 +01:00 коммит произвёл git
Родитель a86ad47c94
Коммит 5880103450
2 изменённых файлов: 25 добавлений и 3 удалений

Просмотреть файл

@ -50,7 +50,6 @@ class Gem::Uninstaller
@gem = gem
@version = options[:version] || Gem::Requirement.default
@gem_home = File.realpath(options[:install_dir] || Gem.dir)
@plugins_dir = Gem.plugindir(@gem_home)
@force_executables = options[:executables]
@force_all = options[:all]
@force_ignore = options[:ignore]
@ -284,7 +283,7 @@ class Gem::Uninstaller
def remove_plugins(spec) # :nodoc:
return if spec.plugins.empty?
remove_plugins_for(spec, @plugins_dir)
remove_plugins_for(spec, plugin_dir_for(spec))
end
##
@ -294,7 +293,7 @@ class Gem::Uninstaller
latest = Gem::Specification.latest_spec_for(@spec.name)
return if latest.nil?
regenerate_plugins_for(latest, @plugins_dir)
regenerate_plugins_for(latest, plugin_dir_for(@spec))
end
##
@ -406,4 +405,8 @@ class Gem::Uninstaller
say "Gem #{spec.full_name} cannot be uninstalled because it is a default gem"
end
end
def plugin_dir_for(spec)
Gem.plugindir(spec.base_dir)
end
end

Просмотреть файл

@ -215,6 +215,25 @@ class TestGemUninstaller < Gem::InstallerTestCase
assert File.exist?(plugin_path), "plugin unintentionally removed"
end
def test_remove_plugins_user_installed
write_file File.join(@tempdir, "lib", "rubygems_plugin.rb") do |io|
io.write "# do nothing"
end
@spec.files += %w[lib/rubygems_plugin.rb]
Gem::Installer.at(Gem::Package.build(@spec), force: true, user_install: true).install
plugin_path = File.join Gem.user_dir, "plugins/a_plugin.rb"
assert File.exist?(plugin_path), "plugin not written"
Gem::Specification.dirs = [Gem.dir, Gem.user_dir]
Gem::Uninstaller.new(@spec.name, executables: true, force: true, user_install: true).uninstall
refute File.exist?(plugin_path), "plugin not removed"
end
def test_regenerate_plugins_for
write_file File.join(@tempdir, "lib", "rubygems_plugin.rb") do |io|
io.write "# do nothing"