~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to lib/rubygems/commands/sources_command.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
require 'fileutils'
2
1
require 'rubygems/command'
3
2
require 'rubygems/remote_fetcher'
4
 
require 'rubygems/source_info_cache'
5
3
require 'rubygems/spec_fetcher'
6
4
require 'rubygems/local_remote_options'
7
5
 
10
8
  include Gem::LocalRemoteOptions
11
9
 
12
10
  def initialize
 
11
    require 'fileutils'
 
12
 
13
13
    super 'sources',
14
14
          'Manage the sources and cache file RubyGems uses to search for gems'
15
15
 
51
51
      path = Gem::SpecFetcher.fetcher.dir
52
52
      FileUtils.rm_rf path
53
53
 
54
 
      if not File.exist?(path) then
 
54
      unless File.exist? path then
55
55
        say "*** Removed specs cache ***"
56
 
      elsif not File.writable?(path) then
57
 
        say "*** Unable to remove source cache (write protected) ***"
58
56
      else
59
 
        say "*** Unable to remove source cache ***"
 
57
        unless File.writable? path then
 
58
          say "*** Unable to remove source cache (write protected) ***"
 
59
        else
 
60
          say "*** Unable to remove source cache ***"
 
61
        end
 
62
 
 
63
        terminate_interaction 1
60
64
      end
61
 
 
62
 
      sic = Gem::SourceInfoCache
63
 
      remove_cache_file 'user',          sic.user_cache_file
64
 
      remove_cache_file 'latest user',   sic.latest_user_cache_file
65
 
      remove_cache_file 'system',        sic.system_cache_file
66
 
      remove_cache_file 'latest system', sic.latest_system_cache_file
67
65
    end
68
66
 
69
67
    if options[:add] then
78
76
        say "#{source_uri} added to sources"
79
77
      rescue URI::Error, ArgumentError
80
78
        say "#{source_uri} is not a URI"
 
79
        terminate_interaction 1
81
80
      rescue Gem::RemoteFetcher::FetchError => e
82
 
        yaml_uri = uri + 'yaml'
83
 
        gem_repo = Gem::RemoteFetcher.fetcher.fetch_size yaml_uri rescue false
84
 
 
85
 
        if e.uri =~ /specs\.#{Regexp.escape Gem.marshal_version}\.gz$/ and
86
 
           gem_repo then
87
 
 
88
 
          alert_warning <<-EOF
89
 
RubyGems 1.2+ index not found for:
90
 
\t#{source_uri}
91
 
 
92
 
Will cause RubyGems to revert to legacy indexes, degrading performance.
93
 
          EOF
94
 
 
95
 
          say "#{source_uri} added to sources"
96
 
        else
97
 
          say "Error fetching #{source_uri}:\n\t#{e.message}"
98
 
        end
 
81
        say "Error fetching #{source_uri}:\n\t#{e.message}"
 
82
        terminate_interaction 1
99
83
      end
100
84
    end
101
85
 
115
99
    if options[:update] then
116
100
      fetcher = Gem::SpecFetcher.fetcher
117
101
 
118
 
      if fetcher.legacy_repos.empty? then
119
 
        Gem.sources.each do |update_uri|
120
 
          update_uri = URI.parse update_uri
121
 
          fetcher.load_specs update_uri, 'specs'
122
 
          fetcher.load_specs update_uri, 'latest_specs'
123
 
        end
124
 
      else
125
 
        Gem::SourceInfoCache.cache true
126
 
        Gem::SourceInfoCache.cache.flush
 
102
      Gem.sources.each do |update_uri|
 
103
        update_uri = URI.parse update_uri
 
104
        fetcher.load_specs update_uri, 'specs'
 
105
        fetcher.load_specs update_uri, 'latest_specs'
127
106
      end
128
107
 
129
108
      say "source cache successfully updated"