diff options
author | Hiroshi SHIBATA <[email protected]> | 2021-07-07 14:07:29 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2021-07-07 15:31:52 +0900 |
commit | c082c6eb7c786a432bea23cf78839f64585cb630 (patch) | |
tree | e3c608264fe03645e905fe7284d713cff87b87dd /lib/rubygems | |
parent | 6e2240a2f954c84ed12357382c9c065ae4b91e11 (diff) |
Sync RubyGems and Bundler with upstream
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4634
Diffstat (limited to 'lib/rubygems')
-rw-r--r-- | lib/rubygems/core_ext/tcpsocket_init.rb | 4 | ||||
-rw-r--r-- | lib/rubygems/deprecate.rb | 59 | ||||
-rw-r--r-- | lib/rubygems/gemcutter_utilities.rb | 13 | ||||
-rw-r--r-- | lib/rubygems/installer.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/remote_fetcher.rb | 15 | ||||
-rw-r--r-- | lib/rubygems/request/connection_pools.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/request/http_pool.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/request_set.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/specification.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/uri_parser.rb | 8 | ||||
-rw-r--r-- | lib/rubygems/uri_parsing.rb | 23 | ||||
-rw-r--r-- | lib/rubygems/user_interaction.rb | 2 |
12 files changed, 85 insertions, 49 deletions
diff --git a/lib/rubygems/core_ext/tcpsocket_init.rb b/lib/rubygems/core_ext/tcpsocket_init.rb index 3d9740c579..2a79b63bd6 100644 --- a/lib/rubygems/core_ext/tcpsocket_init.rb +++ b/lib/rubygems/core_ext/tcpsocket_init.rb @@ -11,10 +11,10 @@ module CoreExtensions IPV4_DELAY_SECONDS = 0.1 def initialize(host, serv, *rest) - mutex = Mutex.new + mutex = Thread::Mutex.new addrs = [] threads = [] - cond_var = ConditionVariable.new + cond_var = Thread::ConditionVariable.new Addrinfo.foreach(host, serv, nil, :STREAM) do |addr| Thread.report_on_exception = false if defined? Thread.report_on_exception = () diff --git a/lib/rubygems/deprecate.rb b/lib/rubygems/deprecate.rb index 8c822cda95..5fe0afb6b0 100644 --- a/lib/rubygems/deprecate.rb +++ b/lib/rubygems/deprecate.rb @@ -1,23 +1,70 @@ # frozen_string_literal: true ## -# Provides a single method +deprecate+ to be used to declare when -# something is going away. +# Provides 3 methods for declaring when something is going away. +# +# +deprecate(name, repl, year, month)+: +# Indicate something may be removed on/after a certain date. +# +# +rubygems_deprecate(name, replacement=:none)+: +# Indicate something will be removed in the next major RubyGems version, +# and (optionally) a replacement for it. +# +# +rubygems_deprecate_command+: +# Indicate a RubyGems command (in +lib/rubygems/commands/*.rb+) will be +# removed in the next RubyGems version. +# +# Also provides +skip_during+ for temporarily turning off deprecation warnings. +# This is intended to be used in the test suite, so deprecation warnings +# don't cause test failures if you need to make sure stderr is otherwise empty. +# +# +# Example usage of +deprecate+ and +rubygems_deprecate+: # # class Legacy -# def self.klass_method +# def self.some_class_method # # ... # end # -# def instance_method +# def some_instance_method +# # ... +# end +# +# def some_old_method # # ... # end # # extend Gem::Deprecate -# deprecate :instance_method, "X.z", 2011, 4 +# deprecate :some_instance_method, "X.z", 2011, 4 +# rubygems_deprecate :some_old_method, "Modern#some_new_method" # # class << self # extend Gem::Deprecate -# deprecate :klass_method, :none, 2011, 4 +# deprecate :some_class_method, :none, 2011, 4 +# end +# end +# +# +# Example usage of +rubygems_deprecate_command+: +# +# class Gem::Commands::QueryCommand < Gem::Command +# extend Gem::Deprecate +# rubygems_deprecate_command +# +# # ... +# end +# +# +# Example usage of +skip_during+: +# +# class TestSomething < Gem::Testcase +# def test_some_thing_with_deprecations +# Gem::Deprecate.skip_during do +# actual_stdout, actual_stderr = capture_output do +# Gem.something_deprecated +# end +# assert_empty actual_stdout +# assert_equal(expected, actual_stderr) +# end # end # end diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb index 3687e776e2..00e68916c4 100644 --- a/lib/rubygems/gemcutter_utilities.rb +++ b/lib/rubygems/gemcutter_utilities.rb @@ -52,6 +52,13 @@ module Gem::GemcutterUtilities end ## + # The OTP code from the command options or from the user's configuration. + + def otp + options[:otp] || ENV["GEM_HOST_OTP_CODE"] + end + + ## # The host to connect to either from the RUBYGEMS_HOST environment variable # or from the user's configuration @@ -126,7 +133,7 @@ module Gem::GemcutterUtilities response = rubygems_api_request(:put, "api/v1/api_key", sign_in_host, scope: scope) do |request| request.basic_auth email, password - request["OTP"] = options[:otp] if options[:otp] + request["OTP"] = otp if otp request.body = URI.encode_www_form({:api_key => api_key }.merge(update_scope_params)) end @@ -159,7 +166,7 @@ module Gem::GemcutterUtilities response = rubygems_api_request(:post, "api/v1/api_key", sign_in_host, scope: scope) do |request| request.basic_auth email, password - request["OTP"] = options[:otp] if options[:otp] + request["OTP"] = otp if otp request.body = URI.encode_www_form({ name: key_name }.merge(scope_params)) end @@ -224,7 +231,7 @@ module Gem::GemcutterUtilities request_method = Net::HTTP.const_get method.to_s.capitalize Gem::RemoteFetcher.fetcher.request(uri, request_method) do |req| - req["OTP"] = options[:otp] if options[:otp] + req["OTP"] = otp if otp block.call(req) end end diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 8c286605e1..7cc9bc6a0b 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -68,7 +68,7 @@ class Gem::Installer @path_warning = false - @install_lock = Mutex.new + @install_lock = Thread::Mutex.new class << self ## diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb index e3d4bfbeba..717cb59779 100644 --- a/lib/rubygems/remote_fetcher.rb +++ b/lib/rubygems/remote_fetcher.rb @@ -4,7 +4,7 @@ require 'rubygems/request' require 'rubygems/request/connection_pools' require 'rubygems/s3_uri_signer' require 'rubygems/uri_formatter' -require 'rubygems/uri_parsing' +require 'rubygems/uri_parser' require 'rubygems/user_interaction' require 'resolv' @@ -14,15 +14,12 @@ require 'resolv' class Gem::RemoteFetcher include Gem::UserInteraction - include Gem::UriParsing ## # A FetchError exception wraps up the various possible IO and HTTP failures # that could happen while downloading from the internet. class FetchError < Gem::Exception - include Gem::UriParsing - ## # The URI which was being accessed when the exception happened. @@ -31,7 +28,7 @@ class Gem::RemoteFetcher def initialize(message, uri) super message - uri = parse_uri(uri) + uri = Gem::UriParser.parse_uri(uri) @original_uri = uri.dup @@ -88,7 +85,7 @@ class Gem::RemoteFetcher @proxy = proxy @pools = {} - @pool_lock = Mutex.new + @pool_lock = Thread::Mutex.new @cert_files = Gem::Request.get_cert_files @headers = headers @@ -133,7 +130,7 @@ class Gem::RemoteFetcher require "fileutils" FileUtils.mkdir_p cache_dir rescue nil unless File.exist? cache_dir - source_uri = parse_uri(source_uri) + source_uri = Gem::UriParser.parse_uri(source_uri) scheme = source_uri.scheme @@ -228,7 +225,7 @@ class Gem::RemoteFetcher unless location = response['Location'] raise FetchError.new("redirecting but no redirect location was given", uri) end - location = parse_uri location + location = Gem::UriParser.parse_uri location if https?(uri) && !https?(location) raise FetchError.new("redirecting to non-https resource: #{location}", uri) @@ -246,7 +243,7 @@ class Gem::RemoteFetcher # Downloads +uri+ and returns it as a String. def fetch_path(uri, mtime = nil, head = false) - uri = parse_uri uri + uri = Gem::UriParser.parse_uri uri unless uri.scheme raise ArgumentError, "uri scheme is invalid: #{uri.scheme.inspect}" diff --git a/lib/rubygems/request/connection_pools.rb b/lib/rubygems/request/connection_pools.rb index 7f3988952c..a4c2929b38 100644 --- a/lib/rubygems/request/connection_pools.rb +++ b/lib/rubygems/request/connection_pools.rb @@ -11,7 +11,7 @@ class Gem::Request::ConnectionPools # :nodoc: @proxy_uri = proxy_uri @cert_files = cert_files @pools = {} - @pool_mutex = Mutex.new + @pool_mutex = Thread::Mutex.new end def pool_for(uri) diff --git a/lib/rubygems/request/http_pool.rb b/lib/rubygems/request/http_pool.rb index 9985bbafa6..f028516db8 100644 --- a/lib/rubygems/request/http_pool.rb +++ b/lib/rubygems/request/http_pool.rb @@ -12,7 +12,7 @@ class Gem::Request::HTTPPool # :nodoc: @http_args = http_args @cert_files = cert_files @proxy_uri = proxy_uri - @queue = SizedQueue.new 1 + @queue = Thread::SizedQueue.new 1 @queue << nil end diff --git a/lib/rubygems/request_set.rb b/lib/rubygems/request_set.rb index 5190cfc904..36ec87e1f7 100644 --- a/lib/rubygems/request_set.rb +++ b/lib/rubygems/request_set.rb @@ -151,7 +151,7 @@ class Gem::RequestSet @prerelease = options[:prerelease] requests = [] - download_queue = Queue.new + download_queue = Thread::Queue.new # Create a thread-safe list of gems to download sorted_requests.each do |req| diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 23a37e966b..14226796f1 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -105,7 +105,7 @@ class Gem::Specification < Gem::BasicSpecification # rubocop:disable Style/MutableConstant LOAD_CACHE = {} # :nodoc: # rubocop:enable Style/MutableConstant - LOAD_CACHE_MUTEX = Mutex.new + LOAD_CACHE_MUTEX = Thread::Mutex.new private_constant :LOAD_CACHE if defined? private_constant diff --git a/lib/rubygems/uri_parser.rb b/lib/rubygems/uri_parser.rb index f350edec8c..f51d77a4af 100644 --- a/lib/rubygems/uri_parser.rb +++ b/lib/rubygems/uri_parser.rb @@ -5,10 +5,18 @@ # class Gem::UriParser + def self.parse_uri(source_uri) + return source_uri unless source_uri.is_a?(String) + + new.parse(source_uri) + end + ## # Parses the #uri, raising if it's invalid def parse!(uri) + require "uri" + raise URI::InvalidURIError unless uri # Always escape URI's to deal with potential spaces and such diff --git a/lib/rubygems/uri_parsing.rb b/lib/rubygems/uri_parsing.rb deleted file mode 100644 index 941d7e023a..0000000000 --- a/lib/rubygems/uri_parsing.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -require "rubygems/uri_parser" - -module Gem::UriParsing - - def parse_uri(source_uri) - return source_uri unless source_uri.is_a?(String) - - uri_parser.parse(source_uri) - end - - private :parse_uri - - def uri_parser - require "uri" - - Gem::UriParser.new - end - - private :uri_parser - -end diff --git a/lib/rubygems/user_interaction.rb b/lib/rubygems/user_interaction.rb index 27a9957117..6376ea7cf8 100644 --- a/lib/rubygems/user_interaction.rb +++ b/lib/rubygems/user_interaction.rb @@ -543,7 +543,7 @@ class Gem::StreamUI # A progress reporter that behaves nicely with threaded downloading. class ThreadedDownloadReporter - MUTEX = Mutex.new + MUTEX = Thread::Mutex.new ## # The current file name being displayed |