PHP 8.2.31
Preview: sources_command.rb Size: 3.62 KB
//proc/thread-self/root/opt/alt/ruby20/lib64/ruby/2.0.0/rubygems/commands/sources_command.rb

require 'rubygems/command'
require 'rubygems/remote_fetcher'
require 'rubygems/spec_fetcher'
require 'rubygems/local_remote_options'

class Gem::Commands::SourcesCommand < Gem::Command

  include Gem::LocalRemoteOptions

  def initialize
    require 'fileutils'

    super 'sources',
          'Manage the sources and cache file RubyGems uses to search for gems'

    add_option '-a', '--add SOURCE_URI', 'Add source' do |value, options|
      options[:add] = value
    end

    add_option '-l', '--list', 'List sources' do |value, options|
      options[:list] = value
    end

    add_option '-r', '--remove SOURCE_URI', 'Remove source' do |value, options|
      options[:remove] = value
    end

    add_option '-c', '--clear-all',
               'Remove all sources (clear the cache)' do |value, options|
      options[:clear_all] = value
    end

    add_option '-u', '--update', 'Update source cache' do |value, options|
      options[:update] = value
    end

    add_proxy_option
  end

  def defaults_str
    '--list'
  end

  def execute
    options[:list] = !(options[:add] ||
                       options[:clear_all] ||
                       options[:remove] ||
                       options[:update])

    if options[:clear_all] then
      path = File.join Gem.user_home, '.gem', 'specs'
      FileUtils.rm_rf path

      unless File.exist? path then
        say "*** Removed specs cache ***"
      else
        unless File.writable? path then
          say "*** Unable to remove source cache (write protected) ***"
        else
          say "*** Unable to remove source cache ***"
        end

        terminate_interaction 1
      end
    end

    if source_uri = options[:add] then
      uri = URI source_uri

      if uri.scheme and uri.scheme.downcase == 'http' and
         uri.host.downcase == 'rubygems.org' then
        question = <<-QUESTION.chomp
https://rubygems.org is recommended for security over #{uri}

Do you want to add this insecure source?
        QUESTION

        terminate_interaction 1 unless ask_yes_no question
      end

      source = Gem::Source.new source_uri

      begin
        if Gem.sources.include? source_uri then
          say "source #{source_uri} already present in the cache"
        else
          source.load_specs :released
          Gem.sources << source
          Gem.configuration.write

          say "#{source_uri} added to sources"
        end
      rescue URI::Error, ArgumentError
        say "#{source_uri} is not a URI"
        terminate_interaction 1
      rescue Gem::RemoteFetcher::FetchError => e
        say "Error fetching #{source_uri}:\n\t#{e.message}"
        terminate_interaction 1
      end
    end

    if options[:remove] then
      source_uri = options[:remove]

      unless Gem.sources.include? source_uri then
        say "source #{source_uri} not present in cache"
      else
        Gem.sources.delete source_uri
        Gem.configuration.write

        say "#{source_uri} removed from sources"
      end
    end

    if options[:update] then
      Gem.sources.each_source do |src|
        src.load_specs :released
        src.load_specs :latest
      end

      say "source cache successfully updated"
    end

    if options[:list] then
      say "*** CURRENT SOURCES ***"
      say

      Gem.sources.each do |src|
        say src
      end
    end
  end

  private

  def remove_cache_file(desc, path)
    FileUtils.rm_rf path

    if not File.exist?(path) then
      say "*** Removed #{desc} source cache ***"
    elsif not File.writable?(path) then
      say "*** Unable to remove #{desc} source cache (write protected) ***"
    else
      say "*** Unable to remove #{desc} source cache ***"
    end
  end

end

Directory Contents

Dirs: 0 × Files: 31

Name Size Perms Modified Actions
859 B lrw-r--r-- 2012-11-29 06:52:18
Edit Download
6.41 KB lrw-r--r-- 2013-06-21 16:16:31
Edit Download
2.01 KB lrw-r--r-- 2012-12-23 00:35:09
Edit Download
3.85 KB lrw-r--r-- 2013-01-04 22:58:15
Edit Download
3.12 KB lrw-r--r-- 2012-11-30 00:23:15
Edit Download
3.89 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
4.16 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
1.49 KB lrw-r--r-- 2013-09-15 14:23:26
Edit Download
2.52 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
4.56 KB lrw-r--r-- 2013-07-22 16:33:18
Edit Download
5.45 KB lrw-r--r-- 2012-12-06 05:26:46
Edit Download
696 B lrw-r--r-- 2013-07-22 16:33:18
Edit Download
2.67 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
395 B lrw-r--r-- 2012-11-29 06:52:18
Edit Download
866 B lrw-r--r-- 2012-11-29 06:52:18
Edit Download
1.84 KB lrw-r--r-- 2013-07-22 16:33:18
Edit Download
3.66 KB lrw-r--r-- 2013-08-16 15:35:06
Edit Download
2.02 KB lrw-r--r-- 2013-07-22 16:33:18
Edit Download
8.03 KB lrw-r--r-- 2013-07-25 15:42:22
Edit Download
2.31 KB lrw-r--r-- 2012-12-14 05:09:37
Edit Download
616 B lrw-r--r-- 2013-07-25 15:42:22
Edit Download
2.35 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
12.94 KB lrw-r--r-- 2013-07-22 16:33:18
Edit Download
3.62 KB lrw-r--r-- 2013-03-17 14:18:23
Edit Download
2.93 KB lrw-r--r-- 2013-07-22 16:33:18
Edit Download
704 B lrw-r--r-- 2011-07-27 01:40:07
Edit Download
3.07 KB lrw-r--r-- 2012-12-06 05:26:46
Edit Download
4.06 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
5.80 KB lrw-r--r-- 2013-07-22 16:33:18
Edit Download
1.87 KB lrw-r--r-- 2011-07-27 01:40:07
Edit Download
2.40 KB lrw-r--r-- 2012-11-29 08:10:23
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).