lib/bundler/source/rubygems.rb in bundler-2.5.10 vs lib/bundler/source/rubygems.rb in bundler-2.5.12

- old
+ new

@@ -8,20 +8,21 @@ autoload :Remote, File.expand_path("rubygems/remote", __dir__) # Ask for X gems per API request API_REQUEST_SIZE = 50 - attr_accessor :remotes + attr_reader :remotes def initialize(options = {}) @options = options @remotes = [] @dependency_names = [] @allow_remote = false - @allow_cached = options["allow_cached"] || false + @allow_cached = false @allow_local = options["allow_local"] || false @checksum_store = Checksum::Store.new + @original_remotes = nil Array(options["remotes"]).reverse_each {|r| add_remote(r) } end def caches @@ -48,14 +49,15 @@ @specs = nil @allow_remote = true end def cached! + return unless File.exist?(cache_path) + return if @allow_cached @specs = nil - @allow_local = true @allow_cached = true end def hash @remotes.hash @@ -91,14 +93,19 @@ def self.from_lock(options) options["remotes"] = Array(options.delete("remote")).reverse new(options) end + def remotes=(new_remotes) + @original_remotes = @remotes + @remotes = new_remotes + end + def to_lock out = String.new("GEM\n") - remotes.reverse_each do |remote| - out << " remote: #{remove_auth remote}\n" + lockfile_remotes.reverse_each do |remote| + out << " remote: #{remote}\n" end out << " specs:\n" end def to_s @@ -133,24 +140,21 @@ # sources, and large_idx.merge! small_idx is way faster than # small_idx.merge! large_idx. index = @allow_remote ? remote_specs.dup : Index.new index.merge!(cached_specs) if @allow_cached index.merge!(installed_specs) if @allow_local + + # complete with default specs, only if not already available in the + # index through remote, cached, or installed specs + index.use(default_specs) if @allow_local + index end end def install(spec, options = {}) - force = options[:force] - ensure_builtin_gems_cached = options[:ensure_builtin_gems_cached] - - if ensure_builtin_gems_cached && spec.default_gem? && !cached_path(spec) - cached_built_in_gem(spec) unless spec.remote - force = true - end - - if installed?(spec) && !force + if (spec.default_gem? && !cached_built_in_gem(spec)) || (installed?(spec) && !options[:force]) print_using_message "Using #{version_message(spec, options[:previous_spec])}" return nil # no post-install message end if spec.remote @@ -359,21 +363,30 @@ end end def installed_specs @installed_specs ||= Index.build do |idx| - Bundler.rubygems.all_specs.reverse_each do |spec| + Bundler.rubygems.installed_specs.reverse_each do |spec| spec.source = self if Bundler.rubygems.spec_missing_extensions?(spec, false) Bundler.ui.debug "Source #{self} is ignoring #{spec} because it is missing extensions" next end idx << spec end end end + def default_specs + @default_specs ||= Index.build do |idx| + Bundler.rubygems.default_specs.each do |spec| + spec.source = self + idx << spec + end + end + end + def cached_specs @cached_specs ||= begin idx = Index.new Dir["#{cache_path}/*.gem"].each do |gemfile| @@ -453,9 +466,13 @@ def cache_path Bundler.app_cache end private + + def lockfile_remotes + @original_remotes || credless_remotes + end # Checks if the requested spec exists in the global cache. If it does, # we copy it to the download path, and if it does not, we download it. # # @param [Specification] spec