summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2024-07-05 16:20:01 +0200
committergit <svn-admin@ruby-lang.org>2024-07-08 17:06:25 +0000
commit39826f384a2a5243530ba99a69b112fb3773b633 (patch)
tree6676186c5c1586d74434b12b4b75bd1ca43b60f4 /lib
parent0c61e212770092269597882dfe2321a1028ab291 (diff)
[rubygems/rubygems] Backport binstub race condition fix to Bundler
https://github.com/rubygems/rubygems/commit/b07e46820d
Diffstat (limited to 'lib')
-rw-r--r--lib/bundler/rubygems_ext.rb21
-rw-r--r--lib/bundler/rubygems_gem_installer.rb20
2 files changed, 41 insertions, 0 deletions
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