Skip to content

Commit 5947d80

Browse files
Merge pull request #7879 from rubygems/deivid-rodriguez/always-leave-default-gem-executables-around
Always leave default gem executables around (cherry picked from commit 33f79f3)
1 parent 54b7a27 commit 5947d80

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/rubygems/uninstaller.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,15 @@ def remove(spec)
251251
raise Gem::FilePermissionError, spec.base_dir unless
252252
File.writable?(spec.base_dir)
253253

254-
safe_delete { FileUtils.rm_r spec.full_gem_path }
254+
full_gem_path = spec.full_gem_path
255+
exclusions = []
256+
257+
if default_spec_matches?(spec) && spec.executables.any?
258+
exclusions = spec.executables.map {|exe| File.join(spec.bin_dir, exe) }
259+
exclusions << File.dirname(exclusions.last) until exclusions.last == full_gem_path
260+
end
261+
262+
safe_delete { rm_r full_gem_path, exclusions: exclusions }
255263
safe_delete { FileUtils.rm_r spec.extension_dir }
256264

257265
old_platform_name = spec.original_name
@@ -378,6 +386,12 @@ def safe_delete(&block)
378386

379387
private
380388

389+
def rm_r(path, exclusions:)
390+
FileUtils::Entry_.new(path).postorder_traverse do |ent|
391+
ent.remove unless exclusions.include?(ent.path)
392+
end
393+
end
394+
381395
def specification_record
382396
@specification_record ||= @install_dir ? Gem::SpecificationRecord.from_path(@install_dir) : Gem::Specification.specification_record
383397
end

test/rubygems/test_gem_commands_uninstall_command.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def test_execute_does_not_remove_default_gem_executables
102102
end
103103

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

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

0 commit comments

Comments
 (0)