aboutsummaryrefslogtreecommitdiffstats
path: root/lib/rubygems.rb
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-18 05:11:55 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-06-18 05:11:55 +0000
commit85b29e19a3a95294c54a0204bb94ce31bd7369b7 (patch)
treeb7bf99329ed8c29768f2502d3bd418e57be32268 /lib/rubygems.rb
parente255ee2321e51eaf05c364c99b4fe7fdf31a503c (diff)
downloadruby-85b29e19a3a95294c54a0204bb94ce31bd7369b7.tar.gz
* lib/rubygems.rb, lib/rubygems/*, test/rubygems/*: Update rubygems
HEAD(2c6d256). It contains to update vendored Molinillo to 0.5.0. https://github.com/rubygems/rubygems/pull/1638 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55441 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems.rb')
-rw-r--r--lib/rubygems.rb42
1 files changed, 41 insertions, 1 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index e6cc859cbe..b041dd1042 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -154,6 +154,26 @@ module Gem
specifications/default
]
+ ##
+ # Exception classes used in a Gem.read_binary +rescue+ statement. Not all of
+ # these are defined in Ruby 1.8.7, hence the need for this convoluted setup.
+
+ READ_BINARY_ERRORS = begin
+ read_binary_errors = [Errno::EACCES]
+ read_binary_errors << Errno::ENOTSUP if Errno.const_defined?(:ENOTSUP)
+ read_binary_errors
+ end.freeze
+
+ ##
+ # Exception classes used in Gem.write_binary +rescue+ statement. Not all of
+ # these are defined in Ruby 1.8.7.
+
+ WRITE_BINARY_ERRORS = begin
+ write_binary_errors = []
+ write_binary_errors << Errno::ENOTSUP if Errno.const_defined?(:ENOTSUP)
+ write_binary_errors
+ end.freeze
+
@@win_platform = nil
@configuration = nil
@@ -829,7 +849,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
f.flock(File::LOCK_EX)
f.read
end
- rescue Errno::EACCES
+ rescue *READ_BINARY_ERRORS
open path, 'rb' do |f|
f.read
end
@@ -844,6 +864,26 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
end
##
+ # Safely write a file in binary mode on all platforms.
+ def self.write_binary(path, data)
+ open(path, 'wb') do |io|
+ begin
+ io.flock(File::LOCK_EX)
+ rescue *WRITE_BINARY_ERRORS
+ end
+ io.write data
+ end
+ rescue Errno::ENOLCK # NFS
+ if Thread.main != Thread.current
+ raise
+ else
+ open(path, 'wb') do |io|
+ io.write data
+ end
+ end
+ end
+
+ ##
# The path to the running Ruby interpreter.
def self.ruby