Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
Gem.open_file_with_flock
open_file_with_flock(path) { |io| ... }
lib/rubygems.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.4.1/lib/rubygems.rb, line 811
def self.open_file_with_flock(path, &block)
# 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
end
yield io
end
end
Open a file with given flags, and protect access with flock