[前][次][番号順一覧][スレッド一覧]

ruby-changes:70501

From: Hiroshi <ko1@a...>
Date: Fri, 24 Dec 2021 10:35:49 +0900 (JST)
Subject: [ruby-changes:70501] b0ad6cb371 (master): Merge RubyGems-3.3.2 and Bundler-2.3.2

https://git.ruby-lang.org/ruby.git/commit/?id=b0ad6cb371

From b0ad6cb371747a04eb12580e74c73179173cc89d Mon Sep 17 00:00:00 2001
From: Hiroshi SHIBATA <hsbt@r...>
Date: Fri, 24 Dec 2021 09:32:59 +0900
Subject: Merge RubyGems-3.3.2 and Bundler-2.3.2

---
 lib/bundler/definition.rb                          |  5 +-
 lib/bundler/version.rb                             |  2 +-
 lib/rubygems.rb                                    | 54 +++++++++-------------
 lib/rubygems/exceptions.rb                         | 10 ++--
 lib/rubygems/specification.rb                      |  2 +-
 lib/rubygems/stub_specification.rb                 |  2 +-
 spec/bundler/lock/lockfile_spec.rb                 |  7 +--
 test/rubygems/test_gem_commands_install_command.rb | 33 +++++++++++++
 test/rubygems/test_gem_installer.rb                | 27 -----------
 tool/bundler/rubocop_gems.rb.lock                  |  2 +-
 tool/bundler/standard_gems.rb.lock                 |  2 +-
 tool/bundler/test_gems.rb.lock                     |  2 +-
 12 files changed, 72 insertions(+), 76 deletions(-)

diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index 9a94bd3ed3a..5cde1285a66 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -292,10 +292,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/definition.rb#L292
         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 bfe7ae7f7c3..a7ccc9c2012 100644
--- a/lib/bundler/version.rb
+++ b/lib/bundler/version.rb
@@ -1,7 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/bundler/version.rb#L1
 # 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 2e13c589b3a..762ecdf857b 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -8,7 +8,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L8
 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 https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L163
     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]} https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L766
   # 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 20e4049e488..18068690980 100644
--- a/lib/rubygems/exceptions.rb
+++ b/lib/rubygems/exceptions.rb
@@ -24,10 +24,14 @@ class Gem::UnknownCommandError < Gem::Exception https://github.com/ruby/ruby/blob/trunk/lib/rubygems/exceptions.rb#L24
     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 f162eb4a84c..031a37f7750 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -1116,7 +1116,7 @@ class Gem::Specification < Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L1116
     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 4246f9de862..47fe7da695b 100644
--- a/lib/rubygems/stub_specification.rb
+++ b/lib/rubygems/stub_specification.rb
@@ -110,7 +110,7 @@ class Gem::StubSpecification < Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/stub_specification.rb#L110
       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 a2a50d4cf0b..b9ef6e885a1 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 https://github.com/ruby/ruby/blob/trunk/spec/bundler/lock/lockfile_spec.rb#L225
     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 https://github.com/ruby/ruby/blob/trunk/spec/bundler/lock/lockfile_spec.rb#L253
       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 535180983b1..0365b2c4087 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 https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_commands_install_command.rb#L782
     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 dae2b070d57..8874577aa8a 100644
--- a/test/rubygems/test_gem_installer.rb
+++ b/test/rubygems/test_gem_installer.rb
@@ -288,33 +288,6 @@ gem 'other', version https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_installer.rb#L288
                  "(SyntaxError)", e.message
   end
 
-  def test_ensure_no_race_conditions_between_installing_and_loading_gemspecs
-    a, a_gem = u (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]