30
  X   ˆl–Ãa¾”ªi?u8 ¸Ûw˜´o“þZ”8àYŽ6ÄóQ”«MìÕÿ?Ã{‹„„-i[D<†ªoZƒ›Ù«Ä562_‹I|¥Žƒî4ÃVŸÄÃ 2    ‹      }T]kÛ0}Ï¯¸ó ÈÔ8Ûk‚¥ôm%Û²=•bùºqq%OIC›ÿ¾{ã�ÄÉ6a0’ÎÕ9÷øÈQpÎÛJùh>ÙHyŽ¯uá á×•ƒ«+àw:ìÄðþ¢ZùÊh1¼M€—·�¥—¾R|ÄU$°ê‘<Î‘‹Õ3*Ÿ:ôß¬ñÆï\”Ä4ðo$°áý<ŸÁÃ#ì¡ÒÎK­Ð”pc­Ü±ÞV(Ò¡Ž¸VsØÇçg_•Æ‚à®bá¥ªÑélz‘éZºÅV“è­ß¥JÖµX%ÐÄ1Í#ÓÑ‹ç�E¬[Ð²¶˜ÚÁþí!ëaÔû
>dD=6bÚ5ê:uê×ÖlAã~Rñ�µÆŠè¶–ÎAÿñ7²\Ã’Ò¡Ÿñ^Óœò �	Ê�ï6(OÑÃ$Q<ÿû×=mmätžsxÚx�˜AA~øâè6»	Y×|éS£,J�,r"ÏÇøã,94Í¬G£÷± IwN�e¥±ÿ–_c½K ¢ð»{S„£„ì™éEJÒ|ÒÓï.ÕÉ}lLUÀ§öjÝ¸�VÃfþ™¶-þ•E¥Óñ.{É5žÜ»Ü’Ùça¸žb\“@‡k;ÊÇ(q«.wmÝ�!NT»”Ê¦©w‡¿CÒ>…Ô¾ý-ðZgíi„Çddº87#/Äÿ3õü´éô#8¬Â{RFiýõãk6¥Ï.}‘ÍïÍhƒð    D   ˆl–ßi~””†»%�À¶¦-ÿ�þBá%Y¹ë!+ÍÊ2ùÇƒmæ_Æ_�uÐb&=LyZËcõÆÅ Ï    # frozen_string_literal: true

require_relative "text"
##
# A Source knows how to list and fetch gems from a RubyGems marshal index.
#
# There are other Source subclasses for installed gems, local gems, the
# bundler dependency API and so-forth.

class Gem::Source
  include Comparable
  include Gem::Text

  FILES = { # :nodoc:
    :released   => 'specs',
    :latest     => 'latest_specs',
    :prerelease => 'prerelease_specs',
  }.freeze

  ##
  # The URI this source will fetch gems from.

  attr_reader :uri

  ##
  # Creates a new Source which will use the index located at +uri+.

  def initialize(uri)
    begin
      unless uri.kind_of? URI
        uri = URI.parse(uri.to_s)
      end
    rescue URI::InvalidURIError
      raise if Gem::Source == self.class
    end

    @uri = uri
    @update_cache = nil
  end

  ##
  # Sources are ordered by installation preference.

  def <=>(other)
    case other
    when Gem::Source::Installed,
         Gem::Source::Local,
         Gem::Source::Lock,
         Gem::Source::SpecificFile,
         Gem::Source::Git,
         Gem::Source::Vendor then
      -1
    when Gem::Source then
      if !@uri
        return 0 unless other.uri
        return 1
      end

      return -1 if !other.uri

      # Returning 1 here ensures that when sorting a list of sources, the
      # original ordering of sources supplied by the user is preserved.
      return 1 unless @uri.to_s == other.uri.to_s

      0
    else
      nil
    end
  end

  def ==(other) # :nodoc:
    self.class === other and @uri == other.uri
  end

  alias_method :eql?, :== # :nodoc:

  ##
  # Returns a Set that can fetch specifications from this source.

  def dependency_resolver_set # :nodoc:
    return Gem::Resolver::IndexSet.new self if 'file' == uri.scheme

    fetch_uri = if uri.host == "rubygems.org"
      index_uri = uri.dup
      index_uri.host = "index.rubygems.org"
      index_uri
    else
      uri
    end

    bundler_api_uri = enforce_trailing_slash(fetch_uri)

    begin
      fetcher = Gem::RemoteFetcher.fetcher
      response = fetcher.fetch_path bundler_api_uri, nil, true
    rescue Gem::RemoteFetcher::FetchError
      Gem::Resolver::IndexSet.new self
    else
      Gem::Resolver::APISet.new response.uri + "./info/"
    end
  end

  def hash # :nodoc:
    @uri.hash
  end

  ##
  # Returns the local directory to write +uri+ to.

  def cache_dir(uri)
    # Correct for windows paths
    escaped_path = uri.path.sub(/^\/([a-z]):\//i, '/\\1-/')
    escaped_path.tap(&Gem::UNTAINT)

    File.join Gem.spec_cache_dir, "#{uri.host}%#{uri.port}", File.dirname(escaped_path)
  end

  ##
  # Returns true when it is possible and safe to update the cache directory.

  def update_cache?
    return @update_cache unless @update_cache.nil?
    @update_cache =
      begin
        File.stat(Gem.user_home).uid == Process.uid
      rescue Errno::ENOENT
        false
      end
  end

  ##
  # Fetches a specification for the given +name_tuple+.

  def fetch_spec(name_tuple)
    fetcher = Gem::RemoteFetcher.fetcher

    spec_file_name = name_tuple.spec_name

    source_uri = enforce_trailing_slash(uri) + "#{Gem::MARSHAL_SPEC_DIR}#{spec_file_name}"

    cache_dir = cache_dir source_uri

    local_spec = File.join cache_dir, spec_file_name

    if File.exist? local_spec
      spec = Gem.read_binary local