summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2021-12-24 09:32:59 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2021-12-24 10:35:31 +0900
commitb0ad6cb371747a04eb12580e74c73179173cc89d (patch)
treeee873d5c682c4665c838e3ea43585536229a5509
parentde0523feddf740d28fe772f3a22ff9907f88bf69 (diff)
downloadruby-b0ad6cb371747a04eb12580e74c73179173cc89d.tar.gz
Merge RubyGems-3.3.2 and Bundler-2.3.2
-rw-r--r--lib/bundler/definition.rb5
-rw-r--r--lib/bundler/version.rb2
-rw-r--r--lib/rubygems.rb54
-rw-r--r--lib/rubygems/exceptions.rb10
-rw-r--r--lib/rubygems/specification.rb2
-rw-r--r--lib/rubygems/stub_specification.rb2
-rw-r--r--spec/bundler/lock/lockfile_spec.rb7
-rw-r--r--test/rubygems/test_gem_commands_install_command.rb33
-rw-r--r--test/rubygems/test_gem_installer.rb27
-rw-r--r--tool/bundler/rubocop_gems.rb.lock2
-rw-r--r--tool/bundler/standard_gems.rb.lock2
-rw-r--r--tool/bundler/test_gems.rb.lock2
12 files changed, 72 insertions, 76 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 9a94bd3ed3..5cde1285a6 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -292,10 +292,7 @@ module Bundler
locked_major = @locked_bundler_version.segments.first
current_major = Gem::Version.create(Bundler::VERSION).segments.first
- if updating_major = locked_major < current_major
- Bundler.ui.warn "Warning: the lockfile is being updated to Bundler #{current_major}, " \
- "after which you will be unable to return to Bundler #{locked_major}."
- end
+ updating_major = locked_major < current_major
end
preserve_unknown_sections ||= !updating_major && (Bundler.frozen_bundle? || !(unlocking? || @unlocking_bundler))
diff --git a/lib/bundler/version.rb b/lib/bundler/version.rb
index bfe7ae7f7c..a7ccc9c201 100644
--- a/lib/bundler/version.rb
+++ b/lib/bundler/version.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: false
module Bundler
- VERSION = "2.3.1".freeze
+ VERSION = "2.3.2".freeze
def self.bundler_major_version
@bundler_major_version ||= VERSION.split(".").first.to_i
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index 2e13c589b3..762ecdf857 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -8,7 +8,7 @@
require 'rbconfig'
module Gem
- VERSION = "3.3.1".freeze
+ VERSION = "3.3.2".freeze
end
# Must be first since it unloads the prelude from 1.9.2
@@ -163,16 +163,6 @@ module Gem
specifications/default
].freeze
- ##
- # Exception classes used in a Gem.read_binary +rescue+ statement
-
- READ_BINARY_ERRORS = [Errno::EACCES, Errno::EROFS, Errno::ENOSYS, Errno::ENOTSUP].freeze
-
- ##
- # Exception classes used in Gem.write_binary +rescue+ statement
-
- WRITE_BINARY_ERRORS = [Errno::ENOSYS, Errno::ENOTSUP].freeze
-
@@win_platform = nil
@configuration = nil
@@ -776,40 +766,42 @@ 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)
- File.open path, 'rb+' do |f|
- f.flock(File::LOCK_EX)
- f.read
- end
- rescue *READ_BINARY_ERRORS
- File.open path, 'rb' do |f|
- f.read
+ open_with_flock(path, 'rb+') do |io|
+ io.read
end
- rescue Errno::ENOLCK # NFS
- if Thread.main != Thread.current
- raise
- else
- File.open path, 'rb' do |f|
- f.read
- end
+ rescue Errno::EACCES, Errno::EROFS
+ open_with_flock(path, 'rb') do |io|
+ io.read
end
end
##
# Safely write a file in binary mode on all platforms.
def self.write_binary(path, data)
- File.open(path, File::RDWR | File::CREAT | File::LOCK_EX, binmode: true) do |io|
+ open_with_flock(path, 'wb') do |io|
io.write data
end
- rescue *WRITE_BINARY_ERRORS
- File.open(path, 'wb') do |io|
- io.write data
+ end
+
+ ##
+ # Open a file with given flags, and protect access with flock
+
+ def self.open_with_flock(path, flags, &block)
+ File.open(path, flags) do |io|
+ unless java_platform?
+ begin
+ io.flock(File::LOCK_EX)
+ rescue Errno::ENOSYS, Errno::ENOTSUP
+ end
+ end
+ yield io
end
rescue Errno::ENOLCK # NFS
if Thread.main != Thread.current
raise
else
- File.open(path, 'wb') do |io|
- io.write data
+ File.open(path, flags) do |io|
+ yield io
end
end
end
diff --git a/lib/rubygems/exceptions.rb b/lib/rubygems/exceptions.rb
index 20e4049e48..1806869098 100644
--- a/lib/rubygems/exceptions.rb
+++ b/lib/rubygems/exceptions.rb
@@ -24,10 +24,14 @@ class Gem::UnknownCommandError < Gem::Exception
return if defined?(@attached)
if defined?(DidYouMean::SPELL_CHECKERS) && defined?(DidYouMean::Correctable)
- DidYouMean::SPELL_CHECKERS['Gem::UnknownCommandError'] =
- Gem::UnknownCommandSpellChecker
+ if DidYouMean.respond_to?(:correct_error)
+ DidYouMean.correct_error(Gem::UnknownCommandError, Gem::UnknownCommandSpellChecker)
+ else
+ DidYouMean::SPELL_CHECKERS['Gem::UnknownCommandError'] =
+ Gem::UnknownCommandSpellChecker
- prepend DidYouMean::Correctable
+ prepend DidYouMean::Correctable
+ end
end
@attached = true
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index f162eb4a84..031a37f775 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -1116,7 +1116,7 @@ class Gem::Specification < Gem::BasicSpecification
file = file.dup.tap(&Gem::UNTAINT)
return unless File.file?(file)
- code = File.read file, :mode => 'r:UTF-8:-'
+ code = Gem.open_with_flock(file, 'r:UTF-8:-', &:read)
code.tap(&Gem::UNTAINT)
diff --git a/lib/rubygems/stub_specification.rb b/lib/rubygems/stub_specification.rb
index 4246f9de86..47fe7da695 100644
--- a/lib/rubygems/stub_specification.rb
+++ b/lib/rubygems/stub_specification.rb
@@ -110,7 +110,7 @@ class Gem::StubSpecification < Gem::BasicSpecification
begin
saved_lineno = $.
- File.open loaded_from, OPEN_MODE do |file|
+ Gem.open_with_flock loaded_from, OPEN_MODE do |file|
begin
file.readline # discard encoding line
stubline = file.readline.chomp
diff --git a/spec/bundler/lock/lockfile_spec.rb b/spec/bundler/lock/lockfile_spec.rb
index a2a50d4cf0..b9ef6e885a 100644
--- a/spec/bundler/lock/lockfile_spec.rb
+++ b/spec/bundler/lock/lockfile_spec.rb
@@ -225,7 +225,7 @@ RSpec.describe "the lockfile format" do
G
end
- it "warns when updating bundler major version" do
+ it "update the bundler major version just fine" do
current_version = Bundler::VERSION
older_major = previous_major(current_version)
@@ -253,10 +253,7 @@ RSpec.describe "the lockfile format" do
gem "rack"
G
- expect(err).to include(
- "Warning: the lockfile is being updated to Bundler " \
- "#{current_version.split(".").first}, after which you will be unable to return to Bundler #{older_major.split(".").first}."
- )
+ expect(err).to be_empty
expect(lockfile).to eq <<~G
GEM
diff --git a/test/rubygems/test_gem_commands_install_command.rb b/test/rubygems/test_gem_commands_install_command.rb
index 535180983b..0365b2c408 100644
--- a/test/rubygems/test_gem_commands_install_command.rb
+++ b/test/rubygems/test_gem_commands_install_command.rb
@@ -782,6 +782,39 @@ ERROR: Possible alternatives: non_existent_with_hint
assert_match "1 gem installed", @ui.output
end
+ def test_execute_remote_truncates_existing_gemspecs
+ spec_fetcher do |fetcher|
+ fetcher.gem 'a', 1
+ end
+
+ @cmd.options[:domain] = :remote
+
+ @cmd.options[:args] = %w[a]
+
+ use_ui @ui do
+ assert_raise Gem::MockGemUi::SystemExitException, @ui.error do
+ @cmd.execute
+ end
+ end
+
+ assert_equal %w[a-1], @cmd.installed_specs.map {|spec| spec.full_name }
+ assert_match "1 gem installed", @ui.output
+
+ a1_gemspec = File.join(@gemhome, 'specifications', "a-1.gemspec")
+
+ initial_a1_gemspec_content = File.read(a1_gemspec)
+ modified_a1_gemspec_content = initial_a1_gemspec_content + "\n # AAAAAAA\n"
+ File.write(a1_gemspec, modified_a1_gemspec_content)
+
+ use_ui @ui do
+ assert_raise Gem::MockGemUi::SystemExitException, @ui.error do
+ @cmd.execute
+ end
+ end
+
+ assert_equal initial_a1_gemspec_content, File.read(a1_gemspec)
+ end
+
def test_execute_remote_ignores_files
specs = spec_fetcher do |fetcher|
fetcher.gem 'a', 1
diff --git a/test/rubygems/test_gem_installer.rb b/test/rubygems/test_gem_installer.rb
index dae2b070d5..8874577aa8 100644
--- a/test/rubygems/test_gem_installer.rb
+++ b/test/rubygems/test_gem_installer.rb
@@ -288,33 +288,6 @@ gem 'other', version
"(SyntaxError)", e.message
end
- def test_ensure_no_race_conditions_between_installing_and_loading_gemspecs
- a, a_gem = util_gem 'a', 2
-
- Gem::Installer.at(a_gem).install
-
- t1 = Thread.new do
- 5.times do
- Gem::Installer.at(a_gem).install
- sleep 0.1
- end
- end
-
- t2 = Thread.new do
- _, err = capture_output do
- 20.times do
- Gem::Specification.load(a.spec_file)
- Gem::Specification.send(:clear_load_cache)
- end
- end
-
- assert_empty err
- end
-
- t1.join
- t2.join
- end
-
def test_ensure_loadable_spec_security_policy
pend 'openssl is missing' unless Gem::HAVE_OPENSSL
diff --git a/tool/bundler/rubocop_gems.rb.lock b/tool/bundler/rubocop_gems.rb.lock
index 56f6b9873d..93e22b74ef 100644
--- a/tool/bundler/rubocop_gems.rb.lock
+++ b/tool/bundler/rubocop_gems.rb.lock
@@ -60,4 +60,4 @@ DEPENDENCIES
test-unit
BUNDLED WITH
- 2.3.1
+ 2.3.2
diff --git a/tool/bundler/standard_gems.rb.lock b/tool/bundler/standard_gems.rb.lock
index f0c009898d..497e19af7a 100644
--- a/tool/bundler/standard_gems.rb.lock
+++ b/tool/bundler/standard_gems.rb.lock
@@ -66,4 +66,4 @@ DEPENDENCIES
test-unit
BUNDLED WITH
- 2.3.1
+ 2.3.2
diff --git a/tool/bundler/test_gems.rb.lock b/tool/bundler/test_gems.rb.lock
index 98cc8eab22..66efd03518 100644
--- a/tool/bundler/test_gems.rb.lock
+++ b/tool/bundler/test_gems.rb.lock
@@ -41,4 +41,4 @@ DEPENDENCIES
webrick (= 1.7.0)
BUNDLED WITH
- 2.3.1
+ 2.3.2