Skip to content

Commit

Permalink
[rubygems/rubygems] Never remove executables that may belong to a def…
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez authored and matzbot committed Jun 14, 2024
1 parent 7767b60 commit 62fc473
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rubygems/uninstaller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def uninstall_gem(stub)
# Removes installed executables and batch files (windows only) for +spec+.

def remove_executables(spec)
return if spec.executables.empty?
return if spec.executables.empty? || default_spec_matches?(spec)

executables = spec.executables.clone

Expand Down
8 changes: 7 additions & 1 deletion test/rubygems/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -816,9 +816,15 @@ def unresolved_names
Gem::Specification.unresolved_deps.values.map(&:to_s).sort
end

def new_default_spec(name, version, deps = nil, *files)
def new_default_spec(name, version, deps = nil, *files, executable: false)
spec = util_spec name, version, deps

if executable
spec.executables = %w[executable]

write_file File.join(@tempdir, "bin", "executable")
end

spec.loaded_from = File.join(@gemhome, "specifications", "default", spec.spec_name)
spec.files = files

Expand Down
29 changes: 29 additions & 0 deletions test/rubygems/test_gem_commands_uninstall_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,35 @@ def test_execute_all_named_default_multiple
assert_equal "Successfully uninstalled z-2", output.shift
end

def test_execute_does_not_remove_default_gem_executables
z_1_default = new_default_spec "z", "1", executable: true
install_default_gems z_1_default

z_1, = util_gem "z", "1" do |spec|
util_make_exec spec
end
install_gem z_1, force: true

Gem::Specification.reset

@cmd.options[:all] = true
@cmd.options[:force] = true
@cmd.options[:executables] = true
@cmd.options[:args] = %w[z]

use_ui @ui do
@cmd.execute
end

assert File.exist? File.join(@gemhome, "bin", "executable")

output = @ui.output.split "\n"

refute_includes output, "Removing executable"
assert_equal "Successfully uninstalled z-1", output.shift
assert_equal "There was both a regular copy and a default copy of z-1. The regular copy was successfully uninstalled, but the default copy was left around because default gems can't be removed.", output.shift
end

def test_execute_dependency_order
initial_install

Expand Down

0 comments on commit 62fc473

Please sign in to comment.