summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2024-08-12 20:38:09 +0900
committergit <svn-admin@ruby-lang.org>2024-09-02 17:28:50 +0000
commitc1fecc5eabba5bb22a3ebd5616fa50ad612ef4d9 (patch)
tree848ef6329272081c079a9f74eab5a3e020e31b19 /lib
parent1f00f6a09ef8c973be699ad27ab3df3787b4f7af (diff)
[rubygems/rubygems] Simplify `Gem.read_binary` and `Gem.write_binary`
Since `Gem.open_file` no longer locks the target file and is same as `File.open` now, simply `Gem.read_binary` should read in binary mode. Also the body of `Gem.write_binary` is same as `File.binwrite`. https://github.com/rubygems/rubygems/commit/44df9045df
Diffstat (limited to 'lib')
-rw-r--r--lib/rubygems.rb8
1 files changed, 2 insertions, 6 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index c51ba69203..bd9f240e20 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -773,18 +773,14 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
# Safely read a file in binary mode on all platforms.
def self.read_binary(path)
- open_file(path, "rb+", &:read)
- rescue Errno::EACCES, Errno::EROFS
- open_file(path, "rb", &:read)
+ File.binread(path)
end
##
# Safely write a file in binary mode on all platforms.
def self.write_binary(path, data)
- open_file(path, "wb") do |io|
- io.write data
- end
+ File.binwrite(path, data)
rescue Errno::ENOSPC
# If we ran out of space but the file exists, it's *guaranteed* to be corrupted.
File.delete(path) if File.exist?(path)