From aad4bfd7bc1170394fcedf1997d644f8374ad7b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 9 Oct 2024 09:13:49 +0200 Subject: [PATCH] [rubygems/rubygems] Fix `gem install` on NFS shares NFS shares seem to support flock these days, but they need read-write permissions. https://github.com/rubygems/rubygems/commit/1c492804cd --- lib/bundler/rubygems_ext.rb | 5 ++--- lib/rubygems.rb | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index 14f10af9d7..547102be41 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -36,15 +36,14 @@ module Gem remove_method :open_file_with_flock if Gem.respond_to?(:open_file_with_flock) def open_file_with_flock(path, &block) - mode = IO::RDONLY | IO::APPEND | IO::CREAT | IO::BINARY + # read-write mode is used rather than read-only in order to support NFS + mode = IO::RDWR | IO::APPEND | IO::CREAT | IO::BINARY mode |= IO::SHARE_DELETE if IO.const_defined?(:SHARE_DELETE) File.open(path, mode) do |io| begin io.flock(File::LOCK_EX) rescue Errno::ENOSYS, Errno::ENOTSUP - rescue Errno::ENOLCK # NFS - raise unless Thread.main == Thread.current end yield io end diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 43c0d8f13c..8c3e8bdc68 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -808,15 +808,14 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} # Open a file with given flags, and protect access with flock def self.open_file_with_flock(path, &block) - mode = IO::RDONLY | IO::APPEND | IO::CREAT | IO::BINARY + # read-write mode is used rather than read-only in order to support NFS + mode = IO::RDWR | IO::APPEND | IO::CREAT | IO::BINARY mode |= IO::SHARE_DELETE if IO.const_defined?(:SHARE_DELETE) File.open(path, mode) do |io| begin io.flock(File::LOCK_EX) rescue Errno::ENOSYS, Errno::ENOTSUP - rescue Errno::ENOLCK # NFS - raise unless Thread.main == Thread.current end yield io end