diff options
Diffstat (limited to 'lib')
29 files changed, 165 insertions, 169 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 8b9e870f7b..a7d5d1e64a 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -37,7 +37,7 @@ module Bundler environment_preserver = EnvironmentPreserver.from_env ORIGINAL_ENV = environment_preserver.restore environment_preserver.replace_with_backup - SUDO_MUTEX = Mutex.new + SUDO_MUTEX = Thread::Mutex.new autoload :Definition, File.expand_path("bundler/definition", __dir__) autoload :Dependency, File.expand_path("bundler/dependency", __dir__) diff --git a/lib/bundler/cli/doctor.rb b/lib/bundler/cli/doctor.rb index 2986ddbc99..959b1b5e04 100644 --- a/lib/bundler/cli/doctor.rb +++ b/lib/bundler/cli/doctor.rb @@ -100,8 +100,11 @@ module Bundler files_not_readable_or_writable = [] files_not_rw_and_owned_by_different_user = [] files_not_owned_by_current_user_but_still_rw = [] + broken_symlinks = [] Find.find(Bundler.bundle_path.to_s).each do |f| - if !File.writable?(f) || !File.readable?(f) + if !File.exist?(f) + broken_symlinks << f + elsif !File.writable?(f) || !File.readable?(f) if File.stat(f).uid != Process.uid files_not_rw_and_owned_by_different_user << f else @@ -113,6 +116,13 @@ module Bundler end ok = true + + if broken_symlinks.any? + Bundler.ui.warn "Broken links exist in the Bundler home. Please report them to the offending gem's upstream repo. These files are:\n - #{broken_symlinks.join("\n - ")}" + + ok = false + end + if files_not_owned_by_current_user_but_still_rw.any? Bundler.ui.warn "Files exist in the Bundler home that are owned by another " \ "user, but are still readable/writable. These files are:\n - #{files_not_owned_by_current_user_but_still_rw.join("\n - ")}" diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb index 47c1da10e7..5e39e2a36d 100644 --- a/lib/bundler/cli/install.rb +++ b/lib/bundler/cli/install.rb @@ -104,7 +104,7 @@ module Bundler private def warn_if_root - return if Bundler.settings[:silence_root_warning] || Bundler::WINDOWS || !Process.uid.zero? + return if Bundler.settings[:silence_root_warning] || Gem.win_platform? || !Process.uid.zero? Bundler.ui.warn "Don't run Bundler as root. Bundler can ask for sudo " \ "if it is needed, and installing your bundle as root will break this " \ "application for all non-root users on this machine.", :wrap => true diff --git a/lib/bundler/compact_index_client.rb b/lib/bundler/compact_index_client.rb index cf67f0e7a0..d5dbeb3b10 100644 --- a/lib/bundler/compact_index_client.rb +++ b/lib/bundler/compact_index_client.rb @@ -5,7 +5,7 @@ require "set" module Bundler class CompactIndexClient - DEBUG_MUTEX = Mutex.new + DEBUG_MUTEX = Thread::Mutex.new def self.debug return unless ENV["DEBUG_COMPACT_INDEX"] DEBUG_MUTEX.synchronize { warn("[#{self}] #{yield}") } @@ -25,7 +25,7 @@ module Bundler @endpoints = Set.new @info_checksums_by_name = {} @parsed_checksums = false - @mutex = Mutex.new + @mutex = Thread::Mutex.new end def execution_mode=(block) diff --git a/lib/bundler/current_ruby.rb b/lib/bundler/current_ruby.rb index b8c7cada1c..f84d68e262 100644 --- a/lib/bundler/current_ruby.rb +++ b/lib/bundler/current_ruby.rb @@ -65,19 +65,19 @@ module Bundler end def mswin? - Bundler::WINDOWS + Gem.win_platform? end def mswin64? - Bundler::WINDOWS && Bundler.local_platform != Gem::Platform::RUBY && Bundler.local_platform.os == "mswin64" && Bundler.local_platform.cpu == "x64" + Gem.win_platform? && Bundler.local_platform != Gem::Platform::RUBY && Bundler.local_platform.os == "mswin64" && Bundler.local_platform.cpu == "x64" end def mingw? - Bundler::WINDOWS && Bundler.local_platform != Gem::Platform::RUBY && Bundler.local_platform.os == "mingw32" && Bundler.local_platform.cpu != "x64" + Gem.win_platform? && Bundler.local_platform != Gem::Platform::RUBY && Bundler.local_platform.os == "mingw32" && Bundler.local_platform.cpu != "x64" end def x64_mingw? - Bundler::WINDOWS && Bundler.local_platform != Gem::Platform::RUBY && Bundler.local_platform.os == "mingw32" && Bundler.local_platform.cpu == "x64" + Gem.win_platform? && Bundler.local_platform != Gem::Platform::RUBY && Bundler.local_platform.os == "mingw32" && Bundler.local_platform.cpu == "x64" end (KNOWN_MINOR_VERSIONS + KNOWN_MAJOR_VERSIONS).each do |version| diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 0d7630e20d..8998e3b3ae 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -61,10 +61,8 @@ module Bundler @unlocking_bundler = false @unlocking = unlock else - unlock = unlock.dup @unlocking_bundler = unlock.delete(:bundler) - unlock.delete_if {|_k, v| Array(v).empty? } - @unlocking = !unlock.empty? + @unlocking = unlock.any? {|_k, v| !Array(v).empty? } end @dependencies = dependencies @@ -111,8 +109,8 @@ module Bundler @locked_platforms = [] end - @locked_gem_sources = @locked_sources.select {|s| s.is_a?(Source::Rubygems) } - @multisource_allowed = @locked_gem_sources.any?(&:multiple_remotes?) && Bundler.frozen_bundle? + locked_gem_sources = @locked_sources.select {|s| s.is_a?(Source::Rubygems) } + @multisource_allowed = locked_gem_sources.size == 1 && locked_gem_sources.first.multiple_remotes? && Bundler.frozen_bundle? if @multisource_allowed unless sources.aggregate_global_source? @@ -121,7 +119,7 @@ module Bundler Bundler::SharedHelpers.major_deprecation 2, msg end - @sources.merged_gem_lockfile_sections! + @sources.merged_gem_lockfile_sections!(locked_gem_sources.first) end @unlock[:sources] ||= [] @@ -506,9 +504,6 @@ module Bundler attr_reader :sources private :sources - attr_reader :locked_gem_sources - private :locked_gem_sources - def nothing_changed? !@source_changes && !@dependency_changes && !@new_platform && !@path_changes && !@local_changes && !@locked_specs_incomplete_for_platform end @@ -636,35 +631,11 @@ module Bundler end end - def converge_rubygems_sources - return false unless multisource_allowed? - - return false if locked_gem_sources.empty? - - # Get the RubyGems remotes from the Gemfile - actual_remotes = sources.rubygems_remotes - return false if actual_remotes.empty? - - changes = false - - # If there is a RubyGems source in both - locked_gem_sources.each do |locked_gem_source| - # Merge the remotes from the Gemfile into the Gemfile.lock - changes |= locked_gem_source.replace_remotes(actual_remotes, Bundler.settings[:allow_deployment_source_credential_changes]) - end - - changes - end - def converge_sources - changes = false - - changes |= converge_rubygems_sources - # Replace the sources from the Gemfile with the sources from the Gemfile.lock, # if they exist in the Gemfile.lock and are `==`. If you can't find an equivalent # source in the Gemfile.lock, use the one from the Gemfile. - changes |= sources.replace_sources!(@locked_sources) + changes = sources.replace_sources!(@locked_sources) sources.all_sources.each do |source| # If the source is unlockable and the current command allows an unlock of @@ -913,14 +884,13 @@ module Bundler end def additional_base_requirements_for_resolve - return [] unless @locked_gems + return [] unless @locked_gems && unlocking? && !sources.expired_sources?(@locked_gems.sources) dependencies_by_name = dependencies.inject({}) {|memo, dep| memo.update(dep.name => dep) } @locked_gems.specs.reduce({}) do |requirements, locked_spec| name = locked_spec.name dependency = dependencies_by_name[name] - next requirements unless dependency next requirements if @locked_gems.dependencies[name] != dependency - next requirements if dependency.source.is_a?(Source::Path) + next requirements if dependency && dependency.source.is_a?(Source::Path) dep = Gem::Dependency.new(name, ">= #{locked_spec.version}") requirements[name] = DepProxy.get_proxy(dep, locked_spec.platform) requirements diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 313d1a9a41..dc72bf0d93 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -24,9 +24,6 @@ module Bundler def initialize @source = nil @sources = SourceList.new - - @global_rubygems_sources = [] - @git_sources = {} @dependencies = [] @groups = [] @@ -48,7 +45,6 @@ module Bundler @gemfiles << expanded_gemfile_path contents ||= Bundler.read_file(@gemfile.to_s) instance_eval(contents.dup.tap{|x| x.untaint if RUBY_VERSION < "2.7" }, gemfile.to_s, 1) - check_primary_source_safety rescue Exception => e # rubocop:disable Lint/RescueException message = "There was an error " \ "#{e.is_a?(GemfileEvalError) ? "evaluating" : "parsing"} " \ @@ -168,7 +164,7 @@ module Bundler elsif block_given? with_source(@sources.add_rubygems_source("remotes" => source), &blk) else - @global_rubygems_sources << source + @sources.add_global_rubygems_remote(source) end end @@ -222,6 +218,7 @@ module Bundler end def to_definition(lockfile, unlock) + check_primary_source_safety Definition.new(lockfile, @dependencies, @sources, unlock, @ruby_version, @optional_groups, @gemfiles) end @@ -453,12 +450,7 @@ repo_name ||= user_name end def check_rubygems_source_safety - @sources.global_rubygems_source = @global_rubygems_sources.shift - return if @global_rubygems_sources.empty? - - @global_rubygems_sources.each do |source| - @sources.add_rubygems_remote(source) - end + return unless @sources.aggregate_global_source? if Bundler.feature_flag.bundler_3_mode? msg = "This Gemfile contains multiple primary sources. " \ diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index a88fb91cb5..2624ac4b18 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -135,7 +135,7 @@ module Bundler next end - mode = Bundler::WINDOWS ? "wb:UTF-8" : "w" + mode = Gem.win_platform? ? "wb:UTF-8" : "w" require "erb" content = if RUBY_VERSION >= "2.6" ERB.new(template, :trim_mode => "-").result(binding) @@ -144,7 +144,7 @@ module Bundler end File.write(binstub_path, content, :mode => mode, :perm => 0o777 & ~File.umask) - if Bundler::WINDOWS || options[:all_platforms] + if Gem.win_platform? || options[:all_platforms] prefix = "@ruby -x \"%~f0\" %*\n@exit /b %ERRORLEVEL%\n\n" File.write("#{binstub_path}.cmd", prefix + content, :mode => mode) end @@ -182,7 +182,7 @@ module Bundler executable_path = Pathname(spec.full_gem_path).join(spec.bindir, executable).relative_path_from(bin_path) executable_path = executable_path - mode = Bundler::WINDOWS ? "wb:UTF-8" : "w" + mode = Gem.win_platform? ? "wb:UTF-8" : "w" require "erb" content = if RUBY_VERSION >= "2.6" ERB.new(template, :trim_mode => "-").result(binding) @@ -191,7 +191,7 @@ module Bundler end File.write("#{bin_path}/#{executable}", content, :mode => mode, :perm => 0o755) - if Bundler::WINDOWS || options[:all_platforms] + if Gem.win_platform? || options[:all_platforms] prefix = "@ruby -x \"%~f0\" %*\n@exit /b %ERRORLEVEL%\n\n" File.write("#{bin_path}/#{executable}.cmd", prefix + content, :mode => mode) end diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb index f87faff70c..afc21fd006 100644 --- a/lib/bundler/lockfile_parser.rb +++ b/lib/bundler/lockfile_parser.rb @@ -1,16 +1,5 @@ # frozen_string_literal: true -#-- -# Some versions of the Bundler 1.1 RC series introduced corrupted -# lockfiles. There were two major problems: -# -# * multiple copies of the same GIT section appeared in the lockfile -# * when this happened, those sections got multiple copies of gems -# in those sections. -# -# As a result, Bundler 1.1 contains code that fixes the earlier -# corruption. We will remove this fix-up code in Bundler 1.2. - module Bundler class LockfileParser attr_reader :sources, :dependencies, :specs, :platforms, :bundler_version, :ruby_version @@ -124,12 +113,7 @@ module Bundler @sources << @current_source when GIT @current_source = TYPES[@type].from_lock(@opts) - # Strip out duplicate GIT sections - if @sources.include?(@current_source) - @current_source = @sources.find {|s| s == @current_source } - else - @sources << @current_source - end + @sources << @current_source when GEM @opts["remotes"] = Array(@opts.delete("remote")).reverse @current_source = TYPES[@type].from_lock(@opts) @@ -212,9 +196,7 @@ module Bundler @current_spec = LazySpecification.new(name, version, platform) @current_spec.source = @current_source - # Avoid introducing multiple copies of the same spec (caused by - # duplicate GIT sections) - @specs[@current_spec.identifier] ||= @current_spec + @specs[@current_spec.identifier] = @current_spec elsif spaces.size == 6 version = version.split(",").map(&:strip) if version dep = Gem::Dependency.new(name, version) diff --git a/lib/bundler/plugin/installer.rb b/lib/bundler/plugin/installer.rb index 980b0e29b8..4cb7ddf5d6 100644 --- a/lib/bundler/plugin/installer.rb +++ b/lib/bundler/plugin/installer.rb @@ -77,7 +77,7 @@ module Bundler source_list = SourceList.new source_list.add_git_source(git_source_options) if git_source_options - source_list.global_rubygems_source = rubygems_source if rubygems_source + source_list.add_global_rubygems_remote(rubygems_source) if rubygems_source deps = names.map {|name| Dependency.new name, version } diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb index c95664965c..9828fc885c 100644 --- a/lib/bundler/rubygems_ext.rb +++ b/lib/bundler/rubygems_ext.rb @@ -134,6 +134,8 @@ module Gem class Requirement module OrderIndependentComparison def ==(other) + return unless Gem::Requirement === other + if _requirements_sorted? && other._requirements_sorted? super else diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb index b4bb3d1980..43b193cf1c 100644 --- a/lib/bundler/source/rubygems.rb +++ b/lib/bundler/source/rubygems.rb @@ -252,19 +252,6 @@ module Bundler other_remotes.map(&method(:remove_auth)) == @remotes.map(&method(:remove_auth)) end - def replace_remotes(other_remotes, allow_equivalent = false) - return false if other_remotes == @remotes - - equivalent = allow_equivalent && equivalent_remotes?(other_remotes) - - @remotes = [] - other_remotes.reverse_each do |r| - add_remote r.to_s - end - - !equivalent - end - def spec_names if @allow_remote && dependency_api_available? remote_specs.spec_names diff --git a/lib/bundler/source_list.rb b/lib/bundler/source_list.rb index 9a7f0ea0a2..113d49ba72 100644 --- a/lib/bundler/source_list.rb +++ b/lib/bundler/source_list.rb @@ -28,8 +28,9 @@ module Bundler @merged_gem_lockfile_sections end - def merged_gem_lockfile_sections! + def merged_gem_lockfile_sections!(replacement_source) @merged_gem_lockfile_sections = true + @global_rubygems_source = replacement_source end def aggregate_global_source? @@ -53,18 +54,17 @@ module Bundler end def add_rubygems_source(options = {}) - add_source_to_list Source::Rubygems.new(options), @rubygems_sources + new_source = Source::Rubygems.new(options) + return @global_rubygems_source if @global_rubygems_source == new_source + + add_source_to_list new_source, @rubygems_sources end def add_plugin_source(source, options = {}) add_source_to_list Plugin.source(source).new(options), @plugin_sources end - def global_rubygems_source=(uri) - @global_rubygems_source ||= rubygems_aggregate_class.new("remotes" => uri, "allow_local" => true) - end - - def add_rubygems_remote(uri) + def add_global_rubygems_remote(uri) global_rubygems_source.add_remote(uri) global_rubygems_source end @@ -109,27 +109,26 @@ module Bundler if merged_gem_lockfile_sections? [combine_rubygems_sources] else - rubygems_sources.sort_by(&:to_s).uniq + rubygems_sources.sort_by(&:to_s) end end # Returns true if there are changes def replace_sources!(replacement_sources) - return true if replacement_sources.empty? + return false if replacement_sources.empty? - [path_sources, git_sources, plugin_sources].each do |source_list| - source_list.map! do |source| - replacement_sources.find {|s| s == source } || source - end - end + @path_sources, @git_sources, @plugin_sources = map_sources(replacement_sources) + + different_sources?(lock_sources, replacement_sources) + end - replacement_rubygems = merged_gem_lockfile_sections? && - replacement_sources.detect {|s| s.is_a?(Source::Rubygems) } - @global_rubygems_source = replacement_rubygems if replacement_rubygems + # Returns true if there are changes + def expired_sources?(replacement_sources) + return false if replacement_sources.empty? - return true if !equal_sources?(lock_sources, replacement_sources) && !equivalent_sources?(lock_sources, replacement_sources) + lock_sources = dup_with_replaced_sources(replacement_sources).lock_sources - false + different_sources?(lock_sources, replacement_sources) end def local_only! @@ -146,6 +145,24 @@ module Bundler private + def dup_with_replaced_sources(replacement_sources) + new_source_list = dup + new_source_list.replace_sources!(replacement_sources) + new_source_list + end + + def map_sources(replacement_sources) + [path_sources, git_sources, plugin_sources].map do |sources| + sources.map do |source| + replacement_sources.find {|s| s == source } || source + end + end + end + + def different_sources?(lock_sources, replacement_sources) + !equal_sources?(lock_sources, replacement_sources) && !equivalent_sources?(lock_sources, replacement_sources) + end + def rubygems_aggregate_class Source::Rubygems end diff --git a/lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb b/lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb index 5a9c4a27bb..8210ab4c41 100644 --- a/lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb +++ b/lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb @@ -27,7 +27,7 @@ class Bundler::ConnectionPool # @!visibility private def initialize - @mutex = Mutex.new + @mutex = Thread::Mutex.new @last_time = Time.now.to_f end diff --git a/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb b/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb index f3fe1e04ad..cff8477c1f 100644 --- a/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb +++ b/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb @@ -39,8 +39,8 @@ class Bundler::ConnectionPool::TimedStack @created = 0 @que = [] @max = size - @mutex = Mutex.new - @resource = ConditionVariable.new + @mutex = Thread::Mutex.new + @resource = Thread::ConditionVariable.new @shutdown_block = nil end diff --git a/lib/bundler/worker.rb b/lib/bundler/worker.rb index 10139ed25b..0380096523 100644 --- a/lib/bundler/worker.rb +++ b/lib/bundler/worker.rb @@ -21,8 +21,8 @@ module Bundler # @param func [Proc] job to run in inside the worker pool def initialize(size, name, func) @name = name - @request_queue = Queue.new - @response_queue = Queue.new + @request_queue = Thread::Queue.new + @response_queue = Thread::Queue.new @func = func @size = size @threads = nil diff --git a/lib/rubygems.rb b/lib/rubygems.rb index 3585defd2d..1c5a25fd7f 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -178,7 +178,7 @@ module Gem @configuration = nil @gemdeps = nil @loaded_specs = {} - LOADED_SPECS_MUTEX = Mutex.new + LOADED_SPECS_MUTEX = Thread::Mutex.new @path_to_default_spec_map = {} @platforms = [] @ruby = nil 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 |