summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/rubygems.rb35
-rw-r--r--lib/rubygems/installer.rb2
2 files changed, 20 insertions, 17 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index c3cb1d5f12..6de5b6e68c 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -803,6 +803,25 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
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.
def self.ruby
@@ -1298,22 +1317,6 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
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
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index dd346cda4e..453a18e836 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -222,7 +222,7 @@ class Gem::Installer
ruby_executable = false
existing = nil
- File.open generated_bin, "rb" do |io|
+ Gem.open_file_with_flock generated_bin, "rb+" do |io|
line = io.gets
shebang = /^#!.*ruby/o