[rubygems/rubygems] Move flock logic to its own method
https://github.com/rubygems/rubygems/commit/91274128a8
This commit is contained in:
parent
f41a2c96c3
commit
091a6ea8c1
@ -791,23 +791,14 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
|
|||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Open a file with given flags, and on Windows protect access with flock
|
# Open a file with given flags. It requires special logic on Windows, like
|
||||||
|
# protecting access with flock
|
||||||
|
|
||||||
def self.open_file(path, flags, &block)
|
def self.open_file(path, flags, &block)
|
||||||
File.open(path, flags) do |io|
|
if !java_platform? && win_platform?
|
||||||
if !java_platform? && win_platform?
|
open_file_with_flock(path, flags, &block)
|
||||||
begin
|
|
||||||
io.flock(File::LOCK_EX)
|
|
||||||
rescue Errno::ENOSYS, Errno::ENOTSUP
|
|
||||||
end
|
|
||||||
end
|
|
||||||
yield io
|
|
||||||
end
|
|
||||||
rescue Errno::ENOLCK # NFS
|
|
||||||
if Thread.main != Thread.current
|
|
||||||
raise
|
|
||||||
else
|
else
|
||||||
File.open(path, flags, &block)
|
open_file_without_flock(path, flags, &block)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1307,6 +1298,26 @@ 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)
|
||||||
|
File.open(path, flags, &block)
|
||||||
|
end
|
||||||
|
|
||||||
def already_loaded?(file)
|
def already_loaded?(file)
|
||||||
$LOADED_FEATURES.any? do |feature_path|
|
$LOADED_FEATURES.any? do |feature_path|
|
||||||
feature_path.end_with?(file) && default_gem_load_paths.any? {|load_path_entry| feature_path == "#{load_path_entry}/#{file}" }
|
feature_path.end_with?(file) && default_gem_load_paths.any? {|load_path_entry| feature_path == "#{load_path_entry}/#{file}" }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user