From 30176e3f238f198ae835bf1c593d2ad2dce2df49 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Fri, 16 Aug 2024 20:19:22 +0900 Subject: [PATCH] [rubygems/rubygems] Ensure that the lock file will be removed https://github.com/rubygems/rubygems/commit/2706acb271 --- lib/rubygems/installer.rb | 3 ++- test/rubygems/test_gem_installer.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 8f95bab733..1085f73fca 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -546,7 +546,8 @@ class Gem::Installer file.write app_script_text(filename) file.chmod(options[:prog_mode] || 0o755) end - File.unlink(lock.path) + ensure + FileUtils.rm_f lock.path end verbose bin_script_path diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb index 2f4ff7349d..b83a01c73b 100644 --- a/test/rubygems/test_gem_installer.rb +++ b/test/rubygems/test_gem_installer.rb @@ -1234,6 +1234,34 @@ end assert_path_not_exist(File.join(installer.bin_dir, "executable.lock")) end + def test_install_does_not_leave_lockfile_for_binstub + installer = util_setup_installer + + installer.wrappers = true + + File.class_eval do + alias_method :original_chmod, :chmod + define_method(:chmod) do |mode| + original_chmod(mode) + raise Gem::Ext::BuildError if path.end_with?("/executable") + end + end + + assert_raise(Gem::Ext::BuildError) do + installer.install + end + + assert_path_not_exist(File.join(installer.bin_dir, "executable.lock")) + # TODO: remove already copied files at failures. + # assert_path_not_exist(File.join(installer.bin_dir, "executable")) + ensure + File.class_eval do + remove_method :chmod + alias_method :chmod, :original_chmod + remove_method :original_chmod + end + end + def test_install_with_no_prior_files installer = util_setup_installer