[rubygems/rubygems] Protect binstub access during creation with a flock
https://github.com/rubygems/rubygems/commit/88e3f1d23c
This commit is contained in:
parent
091a6ea8c1
commit
5c826ebea5
@ -802,6 +802,25 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Open a file with given flags, and protect access with flock
|
||||||
|
|
||||||
|
def self.open_file_with_flock(path, flags, &block)
|
||||||
|
File.open(path, flags) do |io|
|
||||||
|
begin
|
||||||
|
io.flock(File::LOCK_EX)
|
||||||
|
rescue Errno::ENOSYS, Errno::ENOTSUP
|
||||||
|
end
|
||||||
|
yield io
|
||||||
|
end
|
||||||
|
rescue Errno::ENOLCK # NFS
|
||||||
|
if Thread.main != Thread.current
|
||||||
|
raise
|
||||||
|
else
|
||||||
|
open_file_without_flock(path, flags, &block)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# The path to the running Ruby interpreter.
|
# The path to the running Ruby interpreter.
|
||||||
|
|
||||||
@ -1298,22 +1317,6 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def open_file_with_flock(path, flags, &block)
|
|
||||||
File.open(path, flags) do |io|
|
|
||||||
begin
|
|
||||||
io.flock(File::LOCK_EX)
|
|
||||||
rescue Errno::ENOSYS, Errno::ENOTSUP
|
|
||||||
end
|
|
||||||
yield io
|
|
||||||
end
|
|
||||||
rescue Errno::ENOLCK # NFS
|
|
||||||
if Thread.main != Thread.current
|
|
||||||
raise
|
|
||||||
else
|
|
||||||
open_file_without_flock(path, flags, &block)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def open_file_without_flock(path, flags, &block)
|
def open_file_without_flock(path, flags, &block)
|
||||||
File.open(path, flags, &block)
|
File.open(path, flags, &block)
|
||||||
end
|
end
|
||||||
|
@ -222,7 +222,7 @@ class Gem::Installer
|
|||||||
ruby_executable = false
|
ruby_executable = false
|
||||||
existing = nil
|
existing = nil
|
||||||
|
|
||||||
File.open generated_bin, "rb" do |io|
|
Gem.open_file_with_flock generated_bin, "rb+" do |io|
|
||||||
line = io.gets
|
line = io.gets
|
||||||
shebang = /^#!.*ruby/o
|
shebang = /^#!.*ruby/o
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user