diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 3f6b2197b7..e131b3ce4c 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -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 diff --git a/lib/bundler/rubygems_gem_installer.rb b/lib/bundler/rubygems_gem_installer.rb index 125c6874a2..4d4fd20fea 100644 --- a/lib/bundler/rubygems_gem_installer.rb +++ b/lib/bundler/rubygems_gem_installer.rb @@ -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