1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[rubygems/rubygems] Rename Gem.open_with_flock to Gem.open_file

Since it only uses `flock` on Windows.

https://github.com/rubygems/rubygems/commit/b877de4d9c
This commit is contained in:
David Rodríguez 2022-01-11 20:11:20 +01:00 committed by git
parent ec5bde1a80
commit 2b7025e680
3 changed files with 7 additions and 7 deletions

View file

@ -759,11 +759,11 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
# Safely read a file in binary mode on all platforms. # Safely read a file in binary mode on all platforms.
def self.read_binary(path) def self.read_binary(path)
open_with_flock(path, 'rb+') do |io| open_file(path, 'rb+') do |io|
io.read io.read
end end
rescue Errno::EACCES, Errno::EROFS rescue Errno::EACCES, Errno::EROFS
open_with_flock(path, 'rb') do |io| open_file(path, 'rb') do |io|
io.read io.read
end end
end end
@ -771,15 +771,15 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
## ##
# Safely write a file in binary mode on all platforms. # Safely write a file in binary mode on all platforms.
def self.write_binary(path, data) def self.write_binary(path, data)
open_with_flock(path, 'wb') do |io| open_file(path, 'wb') do |io|
io.write data io.write data
end end
end end
## ##
# Open a file with given flags, and protect access with flock # Open a file with given flags, and on Windows protect access with flock
def self.open_with_flock(path, flags, &block) def self.open_file(path, flags, &block)
File.open(path, flags) do |io| File.open(path, flags) do |io|
if !java_platform? && win_platform? if !java_platform? && win_platform?
begin begin

View file

@ -1115,7 +1115,7 @@ class Gem::Specification < Gem::BasicSpecification
file = file.dup.tap(&Gem::UNTAINT) file = file.dup.tap(&Gem::UNTAINT)
return unless File.file?(file) return unless File.file?(file)
code = Gem.open_with_flock(file, 'r:UTF-8:-', &:read) code = Gem.open_file(file, 'r:UTF-8:-', &:read)
code.tap(&Gem::UNTAINT) code.tap(&Gem::UNTAINT)

View file

@ -110,7 +110,7 @@ class Gem::StubSpecification < Gem::BasicSpecification
begin begin
saved_lineno = $. saved_lineno = $.
Gem.open_with_flock loaded_from, OPEN_MODE do |file| Gem.open_file loaded_from, OPEN_MODE do |file|
begin begin
file.readline # discard encoding line file.readline # discard encoding line
stubline = file.readline.chomp stubline = file.readline.chomp