summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/rubygems/installer.rb3
-rw-r--r--test/rubygems/test_gem_installer.rb28
2 files changed, 30 insertions, 1 deletions
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