Skip to content

Commit

Permalink
[rubygems/rubygems] Always leave default gem executables around
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez authored and matzbot committed Jul 30, 2024
1 parent ec13ccd commit 3d248b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/rubygems/uninstaller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 251,15 @@ def remove(spec)
raise Gem::FilePermissionError, spec.base_dir unless
File.writable?(spec.base_dir)

safe_delete { FileUtils.rm_r spec.full_gem_path }
full_gem_path = spec.full_gem_path
exclusions = []

if default_spec_matches?(spec) && spec.executables.any?
exclusions = spec.executables.map {|exe| File.join(spec.bin_dir, exe) }
exclusions << File.dirname(exclusions.last) until exclusions.last == full_gem_path
end

safe_delete { rm_r full_gem_path, exclusions: exclusions }
safe_delete { FileUtils.rm_r spec.extension_dir }

old_platform_name = spec.original_name
Expand Down Expand Up @@ -378,6 386,12 @@ def safe_delete(&block)

private

def rm_r(path, exclusions:)
FileUtils::Entry_.new(path).postorder_traverse do |ent|
ent.remove unless exclusions.include?(ent.path)
end
end

def specification_record
@specification_record ||= @install_dir ? Gem::SpecificationRecord.from_path(@install_dir) : Gem::Specification.specification_record
end
Expand Down
1 change: 1 addition & 0 deletions test/rubygems/test_gem_commands_uninstall_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 102,7 @@ def test_execute_does_not_remove_default_gem_executables
end

assert File.exist? File.join(@gemhome, "bin", "executable")
assert File.exist? File.join(@gemhome, "gems", "z-1", "bin", "executable")

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

Expand Down

0 comments on commit 3d248b2

Please sign in to comment.