Skip to content

Commit 5880103

Browse files
voxikmatzbot
authored andcommitted
[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. rubygems/rubygems@6047f78210
1 parent a86ad47 commit 5880103

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

lib/rubygems/uninstaller.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ def initialize(gem, options = {})
5050
@gem = gem
5151
@version = options[:version] || Gem::Requirement.default
5252
@gem_home = File.realpath(options[:install_dir] || Gem.dir)
53-
@plugins_dir = Gem.plugindir(@gem_home)
5453
@force_executables = options[:executables]
5554
@force_all = options[:all]
5655
@force_ignore = options[:ignore]
@@ -284,7 +283,7 @@ def remove(spec)
284283
def remove_plugins(spec) # :nodoc:
285284
return if spec.plugins.empty?
286285

287-
remove_plugins_for(spec, @plugins_dir)
286+
remove_plugins_for(spec, plugin_dir_for(spec))
288287
end
289288

290289
##
@@ -294,7 +293,7 @@ def regenerate_plugins
294293
latest = Gem::Specification.latest_spec_for(@spec.name)
295294
return if latest.nil?
296295

297-
regenerate_plugins_for(latest, @plugins_dir)
296+
regenerate_plugins_for(latest, plugin_dir_for(@spec))
298297
end
299298

300299
##
@@ -406,4 +405,8 @@ def warn_cannot_uninstall_default_gems(specs)
406405
say "Gem #{spec.full_name} cannot be uninstalled because it is a default gem"
407406
end
408407
end
408+
409+
def plugin_dir_for(spec)
410+
Gem.plugindir(spec.base_dir)
411+
end
409412
end

test/rubygems/test_gem_uninstaller.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,25 @@ def test_uninstall_with_install_dir_removes_plugins
215215
assert File.exist?(plugin_path), "plugin unintentionally removed"
216216
end
217217

218+
def test_remove_plugins_user_installed
219+
write_file File.join(@tempdir, "lib", "rubygems_plugin.rb") do |io|
220+
io.write "# do nothing"
221+
end
222+
223+
@spec.files += %w[lib/rubygems_plugin.rb]
224+
225+
Gem::Installer.at(Gem::Package.build(@spec), force: true, user_install: true).install
226+
227+
plugin_path = File.join Gem.user_dir, "plugins/a_plugin.rb"
228+
assert File.exist?(plugin_path), "plugin not written"
229+
230+
Gem::Specification.dirs = [Gem.dir, Gem.user_dir]
231+
232+
Gem::Uninstaller.new(@spec.name, executables: true, force: true, user_install: true).uninstall
233+
234+
refute File.exist?(plugin_path), "plugin not removed"
235+
end
236+
218237
def test_regenerate_plugins_for
219238
write_file File.join(@tempdir, "lib", "rubygems_plugin.rb") do |io|
220239
io.write "# do nothing"

0 commit comments

Comments
 (0)