Skip to content

Commit

Permalink
Update rubygems to 2.7.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed Feb 7, 2018
1 parent b272f2a commit 62a1ea7
Show file tree
Hide file tree
Showing 21 changed files with 71 additions and 46 deletions.
10 changes: 5 additions & 5 deletions library/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require 'thread'

module Gem
VERSION = "2.7.4"
VERSION = "2.7.5"
end

# Must be first since it unloads the prelude from 1.9.2
Expand Down Expand Up @@ -176,7 +176,7 @@ module Gem
write_binary_errors
end.freeze

USE_BUNDLER_FOR_GEMDEPS = true # :nodoc:
USE_BUNDLER_FOR_GEMDEPS = !ENV['DONT_USE_BUNDLER_FOR_GEMDEPS'] # :nodoc:

@@win_platform = nil

Expand Down Expand Up @@ -871,19 +871,19 @@ def self.refresh
# Safely read a file in binary mode on all platforms.

def self.read_binary(path)
open path, 'rb+' do |f|
File.open path, 'rb+' do |f|
f.flock(File::LOCK_EX)
f.read
end
rescue *READ_BINARY_ERRORS
open path, 'rb' do |f|
File.open path, 'rb' do |f|
f.read
end
rescue Errno::ENOLCK # NFS
if Thread.main != Thread.current
raise
else
open path, 'rb' do |f|
File.open path, 'rb' do |f|
f.read
end
end
Expand Down
2 changes: 1 addition & 1 deletion library/rubygems/commands/generate_index_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def execute

if not File.exist?(options[:directory]) or
not File.directory?(options[:directory]) then
alert_error "unknown directory name #{directory}."
alert_error "unknown directory name #{options[:directory]}."
terminate_interaction 1
else
indexer = Gem::Indexer.new options.delete(:directory), options
Expand Down
18 changes: 12 additions & 6 deletions library/rubygems/commands/setup_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,9 @@ def fake_spec.full_gem_path
def install_default_bundler_gem
return unless Gem::USE_BUNDLER_FOR_GEMDEPS

mkdir_p Gem::Specification.default_specifications_dir
specs_dir = Gem::Specification.default_specifications_dir
File.join(options[:destdir], specs_dir) unless Gem.win_platform?
mkdir_p specs_dir

# Workaround for non-git environment.
gemspec = File.open('bundler/bundler.gemspec', 'rb'){|f| f.read.gsub(/`git ls-files -z`/, "''") }
Expand All @@ -361,11 +363,11 @@ def install_default_bundler_gem
bundler_spec.executables -= %w[bundler bundle_ruby]

# Remove bundler-*.gemspec in default specification directory.
Dir.entries(Gem::Specification.default_specifications_dir).
Dir.entries(specs_dir).
select {|gs| gs.start_with?("bundler-") }.
each {|gs| File.delete(File.join(Gem::Specification.default_specifications_dir, gs)) }
each {|gs| File.delete(File.join(specs_dir, gs)) }

default_spec_path = File.join(Gem::Specification.default_specifications_dir, "#{bundler_spec.full_name}.gemspec")
default_spec_path = File.join(specs_dir, "#{bundler_spec.full_name}.gemspec")
Gem.write_binary(default_spec_path, bundler_spec.to_ruby)

bundler_spec = Gem::Specification.load(default_spec_path)
Expand All @@ -383,8 +385,12 @@ def install_default_bundler_gem
each {|default_gem| rm_r File.join(bundler_spec.gems_dir, default_gem) }
end

mkdir_p bundler_spec.bin_dir
bundler_spec.executables.each {|e| cp File.join("bundler", bundler_spec.bindir, e), File.join(bundler_spec.bin_dir, e) }
bundler_bin_dir = File.join(Gem.default_dir, 'gems', bundler_spec.full_name, bundler_spec.bindir)
File.join(options[:destdir], bundler_bin_dir) unless Gem.win_platform?
mkdir_p bundler_bin_dir
bundler_spec.executables.each do |e|
cp File.join("bundler", bundler_spec.bindir, e), File.join(bundler_bin_dir, e)
end

if Gem.win_platform?
require 'rubygems/installer'
Expand Down
4 changes: 2 additions & 2 deletions library/rubygems/commands/unpack_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def execute

spec_file = File.basename spec.spec_file

open spec_file, 'w' do |io|
File.open spec_file, 'w' do |io|
io.write metadata
end
else
Expand Down Expand Up @@ -176,7 +176,7 @@ def get_metadata path, security_policy = nil

metadata = nil

open path, Gem.binary_mode do |io|
File.open path, Gem.binary_mode do |io|
tar = Gem::Package::TarReader.new io
tar.each_entry do |entry|
case entry.full_name
Expand Down
2 changes: 1 addition & 1 deletion library/rubygems/config_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def to_yaml # :nodoc:

# Writes out this config file, replacing its source.
def write
open config_file_name, 'w' do |io|
File.open config_file_name, 'w' do |io|
io.write to_yaml
end
end
Expand Down
2 changes: 1 addition & 1 deletion library/rubygems/ext/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def write_gem_make_out output # :nodoc:

FileUtils.mkdir_p @spec.extension_dir

open destination, 'wb' do |io| io.puts output end
File.open destination, 'wb' do |io| io.puts output end

destination
end
Expand Down
9 changes: 5 additions & 4 deletions library/rubygems/indexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'rubygems'
require 'rubygems/package'
require 'time'
require 'tmpdir'

begin
gem 'builder'
Expand Down Expand Up @@ -64,7 +65,7 @@ def initialize(directory, options = {})
@build_modern = options[:build_modern]

@dest_directory = directory
@directory = File.join(Dir.tmpdir, "gem_generate_index_#{$$}")
@directory = Dir.mktmpdir 'gem_generate_index'

marshal_name = "Marshal.#{Gem.marshal_version}"

Expand Down Expand Up @@ -123,7 +124,7 @@ def build_marshal_gemspecs specs
marshal_name = File.join @quick_marshal_dir, spec_file_name

marshal_zipped = Gem.deflate Marshal.dump(spec)
open marshal_name, 'wb' do |io| io.write marshal_zipped end
File.open marshal_name, 'wb' do |io| io.write marshal_zipped end

files << marshal_name

Expand Down Expand Up @@ -261,7 +262,7 @@ def compress(filename, extension)

zipped = Gem.deflate data

open "#{filename}.#{extension}", 'wb' do |io|
File.open "#{filename}.#{extension}", 'wb' do |io|
io.write zipped
end
end
Expand Down Expand Up @@ -427,7 +428,7 @@ def update_specs_index(index, source, dest)

specs_index = compact_specs specs_index.uniq.sort

open dest, 'wb' do |io|
File.open dest, 'wb' do |io|
Marshal.dump specs_index, io
end
end
Expand Down
13 changes: 9 additions & 4 deletions library/rubygems/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def check_executable_overwrite filename # :nodoc:
ruby_executable = false
existing = nil

open generated_bin, 'rb' do |io|
File.open generated_bin, 'rb' do |io|
next unless io.gets =~ /^#!/ # shebang
io.gets # blankline

Expand Down Expand Up @@ -427,7 +427,7 @@ def default_spec_file
# specifications directory.

def write_spec
open spec_file, 'w' do |file|
File.open spec_file, 'w' do |file|
spec.installed_by_version = Gem.rubygems_version

file.puts spec.to_ruby_for_cache
Expand Down Expand Up @@ -464,7 +464,12 @@ def generate_windows_script(filename, bindir)
def generate_bin # :nodoc:
return if spec.executables.nil? or spec.executables.empty?

Dir.mkdir @bin_dir unless File.exist? @bin_dir
begin
Dir.mkdir @bin_dir
rescue SystemCallError
raise unless File.directory? @bin_dir
end

raise Gem::FilePermissionError.new(@bin_dir) unless File.writable? @bin_dir

spec.executables.each do |filename|
Expand Down Expand Up @@ -863,7 +868,7 @@ def write_build_info_file

build_info_file = File.join build_info_dir, "#{spec.full_name}.info"

open build_info_file, 'w' do |io|
File.open build_info_file, 'w' do |io|
@build_args.each do |arg|
io.puts arg
end
Expand Down
4 changes: 2 additions & 2 deletions library/rubygems/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def add_files tar # :nodoc:
next unless stat.file?

tar.add_file_simple file, stat.mode, stat.size do |dst_io|
open file, 'rb' do |src_io|
File.open file, 'rb' do |src_io|
dst_io.write src_io.read 16384 until src_io.eof?
end
end
Expand Down Expand Up @@ -382,7 +382,7 @@ def extract_tar_gz io, destination_dir, pattern = "*" # :nodoc:

FileUtils.mkdir_p mkdir, mkdir_options

open destination, 'wb' do |out|
File.open destination, 'wb' do |out|
out.write entry.read
FileUtils.chmod entry.header.mode, destination
end if entry.file?
Expand Down
4 changes: 2 additions & 2 deletions library/rubygems/package/file_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def present?
end

def with_write_io &block
open path, 'wb', &block
File.open path, 'wb', &block
end

def with_read_io &block
open path, 'rb', &block
File.open path, 'rb', &block
end

end
Expand Down
2 changes: 1 addition & 1 deletion library/rubygems/package/old.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def extract_files destination_dir

FileUtils.mkdir_p File.dirname destination

open destination, 'wb', entry['mode'] do |out|
File.open destination, 'wb', entry['mode'] do |out|
out.write file_data
end

Expand Down
2 changes: 1 addition & 1 deletion library/rubygems/request_set/lockfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def to_s
def write
content = to_s

open "#{@gem_deps_file}.lock", 'w' do |io|
File.open "#{@gem_deps_file}.lock", 'w' do |io|
io.write content
end
end
Expand Down
2 changes: 1 addition & 1 deletion library/rubygems/security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ def self.trusted_certificates &block
def self.write pemmable, path, permissions = 0600, passphrase = nil, cipher = KEY_CIPHER
path = File.expand_path path

open path, 'wb', permissions do |io|
File.open path, 'wb', permissions do |io|
if passphrase and cipher
io.write pemmable.to_pem cipher, passphrase
else
Expand Down
2 changes: 1 addition & 1 deletion library/rubygems/security/trust_dir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def trust_cert certificate

destination = cert_path certificate

open destination, 'wb', @permissions[:trusted_cert] do |io|
File.open destination, 'wb', @permissions[:trusted_cert] do |io|
io.write certificate.to_pem
end
end
Expand Down
2 changes: 1 addition & 1 deletion library/rubygems/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def fetch_spec name_tuple
if update_cache? then
FileUtils.mkdir_p cache_dir

open local_spec, 'wb' do |io|
File.open local_spec, 'wb' do |io|
io.write spec
end
end
Expand Down
4 changes: 4 additions & 0 deletions library/rubygems/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,9 @@ def test_files= files # :nodoc:
def self._all # :nodoc:
unless defined?(@@all) && @@all then
@@all = stubs.map(&:to_spec)
if @@all.any?(&:nil?) # TODO: remove once we're happy
raise "pid: #{$$} nil spec! included in #{stubs.inspect}"
end

# After a reset, make sure already loaded specs
# are still marked as activated.
Expand Down Expand Up @@ -958,6 +961,7 @@ def self.all
# -- wilsonb

def self.all= specs
raise "nil spec!" if specs.any?(&:nil?) # TODO: remove once we're happy
@@stubs_by_name = specs.group_by(&:name)
@@all = @@stubs = specs
end
Expand Down
2 changes: 2 additions & 0 deletions library/rubygems/stub_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def data
unless @data
begin
saved_lineno = $.

# TODO It should be use `File.open`, but bundler-1.16.1 example expects Kernel#open.
open loaded_from, OPEN_MODE do |file|
begin
file.readline # discard encoding line
Expand Down
22 changes: 14 additions & 8 deletions library/rubygems/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
gem 'json'
end

require 'bundler'
if Gem::USE_BUNDLER_FOR_GEMDEPS
require 'bundler'
end
require 'minitest/autorun'

require 'rubygems/deprecate'
Expand Down Expand Up @@ -235,7 +237,9 @@ def setup
@current_dir = Dir.pwd
@fetcher = nil

Bundler.ui = Bundler::UI::Silent.new
if Gem::USE_BUNDLER_FOR_GEMDEPS
Bundler.ui = Bundler::UI::Silent.new
end
@back_ui = Gem::DefaultUserInteraction.ui
@ui = Gem::MockGemUi.new
# This needs to be a new instance since we call use_ui(@ui) when we want to
Expand Down Expand Up @@ -331,7 +335,9 @@ def setup
Gem.loaded_specs.clear
Gem.clear_default_specs
Gem::Specification.unresolved_deps.clear
Bundler.reset!
if Gem::USE_BUNDLER_FOR_GEMDEPS
Bundler.reset!
end

Gem.configuration.verbose = true
Gem.configuration.update_sources = true
Expand Down Expand Up @@ -482,7 +488,7 @@ def git_gem name = 'a', version = 1

gemspec = "#{name}.gemspec"

open File.join(directory, gemspec), 'w' do |io|
File.open File.join(directory, gemspec), 'w' do |io|
io.write git_spec.to_ruby
end

Expand Down Expand Up @@ -586,7 +592,7 @@ def mu_pp(obj)
# Reads a Marshal file at +path+

def read_cache(path)
open path.dup.untaint, 'rb' do |io|
File.open path.dup.untaint, 'rb' do |io|
Marshal.load io.read
end
end
Expand All @@ -606,7 +612,7 @@ def write_file(path)
dir = File.dirname path
FileUtils.mkdir_p dir unless File.directory? dir

open path, 'wb' do |io|
File.open path, 'wb' do |io|
yield io if block_given?
end

Expand Down Expand Up @@ -721,7 +727,7 @@ def install_default_gems(*specs)
install_default_specs(*specs)

specs.each do |spec|
open spec.loaded_from, 'w' do |io|
File.open spec.loaded_from, 'w' do |io|
io.write spec.to_ruby_for_cache
end
end
Expand Down Expand Up @@ -1357,7 +1363,7 @@ def save_gemspec name = 'a', version = 1, directory = '.'
yield specification if block_given?
end

open File.join(directory, "#{name}.gemspec"), 'w' do |io|
File.open File.join(directory, "#{name}.gemspec"), 'w' do |io|
io.write vendor_spec.to_ruby
end

Expand Down
Loading

0 comments on commit 62a1ea7

Please sign in to comment.