diff options
author | David RodrÃguez <[email protected]> | 2024-07-19 11:59:35 +0200 |
---|---|---|
committer | git <[email protected]> | 2024-07-30 14:01:32 +0000 |
commit | 3d248b2eb3d2b10f9d2ddf614485ceb35089f924 (patch) | |
tree | ce6399b0916a0a34ef7c6b661c90813ff7ea062d | |
parent | ec13ccdf53b327957156a2829064270863b0e309 (diff) |
[rubygems/rubygems] Always leave default gem executables around
https://github.com/rubygems/rubygems/commit/775c35e197
-rw-r--r-- | lib/rubygems/uninstaller.rb | 16 | ||||
-rw-r--r-- | test/rubygems/test_gem_commands_uninstall_command.rb | 1 |
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb index 214ba53a88..471c29b6e4 100644 --- a/lib/rubygems/uninstaller.rb +++ b/lib/rubygems/uninstaller.rb @@ -251,7 +251,15 @@ class Gem::Uninstaller 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 @@ -378,6 +386,12 @@ class Gem::Uninstaller 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 diff --git a/test/rubygems/test_gem_commands_uninstall_command.rb b/test/rubygems/test_gem_commands_uninstall_command.rb index 81fadfcb99..5bbb5856a6 100644 --- a/test/rubygems/test_gem_commands_uninstall_command.rb +++ b/test/rubygems/test_gem_commands_uninstall_command.rb @@ -102,6 +102,7 @@ class TestGemCommandsUninstallCommand < Gem::InstallerTestCase 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" |