[rubygems/rubygems] Backport binstub race condition fix to Bundler

https://github.com/rubygems/rubygems/commit/b07e46820d
This commit is contained in:
David Rodríguez 2024-07-05 16:20:01 +02:00 committed by git
parent 0c61e21277
commit 39826f384a
2 changed files with 41 additions and 0 deletions

View File

@ -30,6 +30,27 @@ module Gem
end
end
# Can be removed once RubyGems 3.5.14 support is dropped
unless Gem.respond_to?(:open_file_with_flock)
def self.open_file_with_flock(path, &block)
flags = File.exist?(path) ? "r+" : "a+"
File.open(path, flags) do |io|
begin
io.flock(File::LOCK_EX)
rescue Errno::ENOSYS, Errno::ENOTSUP
end
yield io
rescue Errno::ENOLCK # NFS
if Thread.main != Thread.current
raise
else
File.open(path, flags, &block)
end
end
end
end
require "rubygems/specification"
# Can be removed once RubyGems 3.5.15 support is dropped

View File

@ -81,6 +81,26 @@ module Bundler
end
end
if Bundler.rubygems.provides?("< 3.5.15")
def generate_bin_script(filename, bindir)
bin_script_path = File.join bindir, formatted_program_filename(filename)
Gem.open_file_with_flock("#{bin_script_path}.lock") do
require "fileutils"
FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers
File.open(bin_script_path, "wb", 0o755) do |file|
file.write app_script_text(filename)
file.chmod(options[:prog_mode] || 0o755)
end
end
verbose bin_script_path
generate_windows_script filename, bindir
end
end
def build_extensions
extension_cache_path = options[:bundler_extension_cache_path]
extension_dir = spec.extension_dir