Parent

Methods

Class Index [+]

Quicksearch

Gem::Commands::MirrorCommand

Public Class Methods

new() click to toggle source
    # File lib/rubygems/commands/mirror_command.rb, line 9
 9:   def initialize
10:     super 'mirror', 'Mirror a gem repository'
11:   end

Public Instance Methods

execute() click to toggle source
     # File lib/rubygems/commands/mirror_command.rb, line 27
 27:   def execute
 28:     config_file = File.join Gem.user_home, '.gemmirrorrc'
 29: 
 30:     raise "Config file #{config_file} not found" unless File.exist? config_file
 31: 
 32:     mirrors = YAML.load_file config_file
 33: 
 34:     raise "Invalid config file #{config_file}" unless mirrors.respond_to? :each
 35: 
 36:     mirrors.each do |mir|
 37:       raise "mirror missing 'from' field" unless mir.has_key? 'from'
 38:       raise "mirror missing 'to' field" unless mir.has_key? 'to'
 39: 
 40:       get_from = mir['from']
 41:       save_to = File.expand_path mir['to']
 42: 
 43:       raise "Directory not found: #{save_to}" unless File.exist? save_to
 44:       raise "Not a directory: #{save_to}" unless File.directory? save_to
 45: 
 46:       gems_dir = File.join save_to, "gems"
 47: 
 48:       if File.exist? gems_dir then
 49:         raise "Not a directory: #{gems_dir}" unless File.directory? gems_dir
 50:       else
 51:         Dir.mkdir gems_dir
 52:       end
 53: 
 54:       source_index_data = ''
 55: 
 56:       say "fetching: #{get_from}/Marshal.#{Gem.marshal_version}.Z"
 57: 
 58:       get_from = URI.parse get_from
 59: 
 60:       if get_from.scheme.nil? then
 61:         get_from = get_from.to_s
 62:       elsif get_from.scheme == 'file' then
 63:         # check if specified URI contains a drive letter (file:/D:/Temp)
 64:         get_from = get_from.to_s
 65:         get_from = if get_from =~ /^file:.*[a-z]:/ then
 66:                      get_from[6..1]
 67:                    else
 68:                      get_from[5..1]
 69:                    end
 70:       end
 71: 
 72:       open File.join(get_from.to_s, "Marshal.#{Gem.marshal_version}.Z"), "rb" do |y|
 73:         source_index_data = Zlib::Inflate.inflate y.read
 74:         open File.join(save_to, "Marshal.#{Gem.marshal_version}"), "wb" do |out|
 75:           out.write source_index_data
 76:         end
 77:       end
 78: 
 79:       source_index = Marshal.load source_index_data
 80: 
 81:       progress = ui.progress_reporter source_index.size,
 82:                                       "Fetching #{source_index.size} gems"
 83:       source_index.each do |fullname, gem|
 84:         gem_file = gem.file_name
 85:         gem_dest = File.join gems_dir, gem_file
 86: 
 87:         unless File.exist? gem_dest then
 88:           begin
 89:             open "#{get_from}/gems/#{gem_file}", "rb" do |g|
 90:               contents = g.read
 91:               open gem_dest, "wb" do |out|
 92:                 out.write contents
 93:               end
 94:             end
 95:           rescue
 96:             old_gf = gem_file
 97:             gem_file = gem_file.downcase
 98:             retry if old_gf != gem_file
 99:             alert_error $!
100:           end
101:         end
102: 
103:         progress.updated gem_file
104:       end
105: 
106:       progress.done
107:     end
108:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.