summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/rubygems.rb12
-rw-r--r--lib/rubygems/commands/generate_index_command.rb2
-rw-r--r--lib/rubygems/commands/setup_command.rb29
-rw-r--r--lib/rubygems/commands/unpack_command.rb4
-rw-r--r--lib/rubygems/config_file.rb2
-rw-r--r--lib/rubygems/ext/builder.rb2
-rw-r--r--lib/rubygems/indexer.rb9
-rw-r--r--lib/rubygems/installer.rb13
-rw-r--r--lib/rubygems/package.rb4
-rw-r--r--lib/rubygems/package/file_source.rb4
-rw-r--r--lib/rubygems/package/old.rb2
-rw-r--r--lib/rubygems/request_set/lockfile.rb2
-rw-r--r--lib/rubygems/security.rb2
-rw-r--r--lib/rubygems/security/trust_dir.rb2
-rw-r--r--lib/rubygems/source.rb2
-rw-r--r--lib/rubygems/stub_specification.rb2
-rw-r--r--lib/rubygems/test_case.rb10
-rw-r--r--lib/rubygems/test_utilities.rb2
-rw-r--r--lib/rubygems/util.rb3
-rw-r--r--lib/rubygems/validator.rb6
20 files changed, 69 insertions, 45 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index 0475ced164..f368226d47 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -10,7 +10,7 @@ require 'rbconfig'
require 'thread'
module Gem
- VERSION = "2.7.3"
+ VERSION = "2.7.5"
end
# Must be first since it unloads the prelude from 1.9.2
@@ -161,7 +161,7 @@ module Gem
# these are defined in Ruby 1.8.7, hence the need for this convoluted setup.
READ_BINARY_ERRORS = begin
- read_binary_errors = [Errno::EACCES, Errno::EROFS]
+ read_binary_errors = [Errno::EACCES, Errno::EROFS, Errno::ENOSYS]
read_binary_errors << Errno::ENOTSUP if Errno.const_defined?(:ENOTSUP)
read_binary_errors
end.freeze
@@ -171,7 +171,7 @@ module Gem
# these are defined in Ruby 1.8.7.
WRITE_BINARY_ERRORS = begin
- write_binary_errors = []
+ write_binary_errors = [Errno::ENOSYS]
write_binary_errors << Errno::ENOTSUP if Errno.const_defined?(:ENOTSUP)
write_binary_errors
end.freeze
@@ -871,19 +871,19 @@ 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 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
diff --git a/lib/rubygems/commands/generate_index_command.rb b/lib/rubygems/commands/generate_index_command.rb
index 01f1f88405..0b677b73a9 100644
--- a/lib/rubygems/commands/generate_index_command.rb
+++ b/lib/rubygems/commands/generate_index_command.rb
@@ -68,7 +68,7 @@ Marshal::MINOR_VERSION constants. It is used to ensure compatibility.
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
diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb
index 5d1414d102..6966cde01a 100644
--- a/lib/rubygems/commands/setup_command.rb
+++ b/lib/rubygems/commands/setup_command.rb
@@ -350,7 +350,9 @@ By default, this RubyGems will install gem as:
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`/, "''") }
@@ -359,23 +361,36 @@ By default, this RubyGems will install gem as:
bundler_spec = Gem::Specification.load("bundler/bundler.gemspec")
bundler_spec.files = Dir.chdir("bundler") { Dir["{*.md,{lib,exe,man}/**/*}"] }
bundler_spec.executables -= %w[bundler bundle_ruby]
- Dir.entries(Gem::Specification.default_specifications_dir).
+
+ # Remove bundler-*.gemspec in default specification directory.
+ 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)
+ # Remove gemspec that was same version of vendored bundler.
+ normal_gemspec = File.join(Gem.default_dir, "specifications", "bundler-#{bundler_spec.version}.gemspec")
+ if File.file? normal_gemspec
+ File.delete normal_gemspec
+ end
+
+ # Remove gem files that were same version of vendored bundler.
if File.directory? bundler_spec.gems_dir
Dir.entries(bundler_spec.gems_dir).
- select {|default_gem| File.basename(default_gem).match(/^bundler-#{Gem::Version::VERSION_PATTERN}$/) }.
+ select {|default_gem| File.basename(default_gem) == "bundler-#{bundler_spec.version}" }.
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'
diff --git a/lib/rubygems/commands/unpack_command.rb b/lib/rubygems/commands/unpack_command.rb
index eb7f550673..b873f20d28 100644
--- a/lib/rubygems/commands/unpack_command.rb
+++ b/lib/rubygems/commands/unpack_command.rb
@@ -94,7 +94,7 @@ command help for an example.
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
@@ -176,7 +176,7 @@ command help for an example.
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
diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb
index a4efed0f5a..c0d19dbfc2 100644
--- a/lib/rubygems/config_file.rb
+++ b/lib/rubygems/config_file.rb
@@ -458,7 +458,7 @@ if you believe they were disclosed to a third party.
# 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
diff --git a/lib/rubygems/ext/builder.rb b/lib/rubygems/ext/builder.rb
index a1619c97d7..eb9db199d5 100644
--- a/lib/rubygems/ext/builder.rb
+++ b/lib/rubygems/ext/builder.rb
@@ -212,7 +212,7 @@ EOF
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
diff --git a/lib/rubygems/indexer.rb b/lib/rubygems/indexer.rb
index 871cc09d8d..3ea994414b 100644
--- a/lib/rubygems/indexer.rb
+++ b/lib/rubygems/indexer.rb
@@ -2,6 +2,7 @@
require 'rubygems'
require 'rubygems/package'
require 'time'
+require 'tmpdir'
begin
gem 'builder'
@@ -64,7 +65,7 @@ class Gem::Indexer
@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}"
@@ -123,7 +124,7 @@ class Gem::Indexer
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
@@ -261,7 +262,7 @@ class Gem::Indexer
zipped = Gem.deflate data
- open "#{filename}.#{extension}", 'wb' do |io|
+ File.open "#{filename}.#{extension}", 'wb' do |io|
io.write zipped
end
end
@@ -427,7 +428,7 @@ class Gem::Indexer
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
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index 0cbca0791b..ee5fedeb64 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -206,7 +206,7 @@ class Gem::Installer
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
@@ -427,7 +427,7 @@ class Gem::Installer
# 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
@@ -464,7 +464,12 @@ class Gem::Installer
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|
@@ -863,7 +868,7 @@ TEXT
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
diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb
index 77811ed5ec..3ac5662b68 100644
--- a/lib/rubygems/package.rb
+++ b/lib/rubygems/package.rb
@@ -219,7 +219,7 @@ class Gem::Package
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
@@ -380,7 +380,7 @@ EOM
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?
diff --git a/lib/rubygems/package/file_source.rb b/lib/rubygems/package/file_source.rb
index 1a4dc4c824..ecc3a68677 100644
--- a/lib/rubygems/package/file_source.rb
+++ b/lib/rubygems/package/file_source.rb
@@ -23,11 +23,11 @@ class Gem::Package::FileSource < Gem::Package::Source # :nodoc: all
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
diff --git a/lib/rubygems/package/old.rb b/lib/rubygems/package/old.rb
index f6e6e67c38..322d682ca8 100644
--- a/lib/rubygems/package/old.rb
+++ b/lib/rubygems/package/old.rb
@@ -80,7 +80,7 @@ class Gem::Package::Old < Gem::Package
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
diff --git a/lib/rubygems/request_set/lockfile.rb b/lib/rubygems/request_set/lockfile.rb
index 7f6eadb939..76ad17d486 100644
--- a/lib/rubygems/request_set/lockfile.rb
+++ b/lib/rubygems/request_set/lockfile.rb
@@ -223,7 +223,7 @@ class Gem::RequestSet::Lockfile
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
diff --git a/lib/rubygems/security.rb b/lib/rubygems/security.rb
index 4690dd9230..236577c5a3 100644
--- a/lib/rubygems/security.rb
+++ b/lib/rubygems/security.rb
@@ -578,7 +578,7 @@ module Gem::Security
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
diff --git a/lib/rubygems/security/trust_dir.rb b/lib/rubygems/security/trust_dir.rb
index bf44975cc6..849cf3cd3e 100644
--- a/lib/rubygems/security/trust_dir.rb
+++ b/lib/rubygems/security/trust_dir.rb
@@ -93,7 +93,7 @@ class Gem::Security::TrustDir
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
diff --git a/lib/rubygems/source.rb b/lib/rubygems/source.rb
index bd84c217a7..b28b850660 100644
--- a/lib/rubygems/source.rb
+++ b/lib/rubygems/source.rb
@@ -160,7 +160,7 @@ class Gem::Source
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
diff --git a/lib/rubygems/stub_specification.rb b/lib/rubygems/stub_specification.rb
index 8337375ab4..ae2effbc84 100644
--- a/lib/rubygems/stub_specification.rb
+++ b/lib/rubygems/stub_specification.rb
@@ -113,6 +113,8 @@ class Gem::StubSpecification < Gem::BasicSpecification
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
diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb
index f7f216e5e3..39aa4fc9a7 100644
--- a/lib/rubygems/test_case.rb
+++ b/lib/rubygems/test_case.rb
@@ -488,7 +488,7 @@ class Gem::TestCase < MiniTest::Unit::TestCase
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
@@ -592,7 +592,7 @@ class Gem::TestCase < MiniTest::Unit::TestCase
# 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
@@ -612,7 +612,7 @@ class Gem::TestCase < MiniTest::Unit::TestCase
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
@@ -727,7 +727,7 @@ class Gem::TestCase < MiniTest::Unit::TestCase
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
@@ -1363,7 +1363,7 @@ Also, a list:
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
diff --git a/lib/rubygems/test_utilities.rb b/lib/rubygems/test_utilities.rb
index 686916ea02..83c9d2d0fe 100644
--- a/lib/rubygems/test_utilities.rb
+++ b/lib/rubygems/test_utilities.rb
@@ -346,7 +346,7 @@ class Gem::TestCase::SpecFetcherSetup
end
def write_spec spec # :nodoc:
- open spec.spec_file, 'w' do |io|
+ File.open spec.spec_file, 'w' do |io|
io.write spec.to_ruby_for_cache
end
end
diff --git a/lib/rubygems/util.rb b/lib/rubygems/util.rb
index 2de45c900b..6c75910004 100644
--- a/lib/rubygems/util.rb
+++ b/lib/rubygems/util.rb
@@ -114,7 +114,8 @@ module Gem::Util
here = File.expand_path directory
loop do
- Dir.chdir here, &block
+ Dir.chdir here, &block rescue Errno::EACCES
+
new_here = File.expand_path('..', here)
return if new_here == here # toplevel
here = new_here
diff --git a/lib/rubygems/validator.rb b/lib/rubygems/validator.rb
index 83448229bb..6842e4fa9c 100644
--- a/lib/rubygems/validator.rb
+++ b/lib/rubygems/validator.rb
@@ -34,7 +34,7 @@ class Gem::Validator
# gem_path:: [String] Path to gem file
def verify_gem_file(gem_path)
- open gem_path, Gem.binary_mode do |file|
+ File.open gem_path, Gem.binary_mode do |file|
gem_data = file.read
verify_gem gem_data
end
@@ -109,7 +109,7 @@ class Gem::Validator
good, gone, unreadable = nil, nil, nil, nil
- open gem_path, Gem.binary_mode do |file|
+ File.open gem_path, Gem.binary_mode do |file|
package = Gem::Package.new gem_path
good, gone = package.contents.partition { |file_name|
@@ -134,7 +134,7 @@ class Gem::Validator
source = File.join gem_directory, entry['path']
- open source, Gem.binary_mode do |f|
+ File.open source, Gem.binary_mode do |f|
unless f.read == data then
errors[gem_name][entry['path']] = "Modified from original"
end