From 8cc45aae947d453acca029e13eb64f3f5f0bf942 Mon Sep 17 00:00:00 2001 From: drbrain Date: Mon, 31 Mar 2008 22:40:06 +0000 Subject: Import RubyGems 1.1.0 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems/indexer/abstract_index_builder.rb | 12 +++++++-- lib/rubygems/indexer/latest_index_builder.rb | 35 ++++++++++++++++++++++++++ lib/rubygems/indexer/master_index_builder.rb | 17 +++++++------ lib/rubygems/indexer/quick_index_builder.rb | 8 +++--- 4 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 lib/rubygems/indexer/latest_index_builder.rb (limited to 'lib/rubygems/indexer') diff --git a/lib/rubygems/indexer/abstract_index_builder.rb b/lib/rubygems/indexer/abstract_index_builder.rb index f25f21707b..5815dcda87 100644 --- a/lib/rubygems/indexer/abstract_index_builder.rb +++ b/lib/rubygems/indexer/abstract_index_builder.rb @@ -22,16 +22,18 @@ class Gem::Indexer::AbstractIndexBuilder @files = [] end + ## # Build a Gem index. Yields to block to handle the details of the # actual building. Calls +begin_index+, +end_index+ and +cleanup+ at # appropriate times to customize basic operations. + def build FileUtils.mkdir_p @directory unless File.exist? @directory raise "not a directory: #{@directory}" unless File.directory? @directory file_path = File.join @directory, @filename - @files << file_path + @files << @filename File.open file_path, "wb" do |file| @file = file @@ -39,14 +41,20 @@ class Gem::Indexer::AbstractIndexBuilder yield end_index end + cleanup ensure @file = nil end + ## # Compress the given file. + def compress(filename, ext="rz") - zipped = zip(File.open(filename, 'rb'){ |fp| fp.read }) + data = open filename, 'rb' do |fp| fp.read end + + zipped = zip data + File.open "#{filename}.#{ext}", "wb" do |file| file.write zipped end diff --git a/lib/rubygems/indexer/latest_index_builder.rb b/lib/rubygems/indexer/latest_index_builder.rb new file mode 100644 index 0000000000..a5798580a6 --- /dev/null +++ b/lib/rubygems/indexer/latest_index_builder.rb @@ -0,0 +1,35 @@ +require 'rubygems/indexer' + +## +# Construct the latest Gem index file. + +class Gem::Indexer::LatestIndexBuilder < Gem::Indexer::AbstractIndexBuilder + + def start_index + super + + @index = Gem::SourceIndex.new + end + + def end_index + super + + latest = @index.latest_specs.sort.map { |spec| spec.original_name } + + @file.write latest.join("\n") + end + + def cleanup + super + + compress @file.path + + @files.delete 'latest_index' # HACK installed via QuickIndexBuilder :/ + end + + def add(spec) + @index.add_spec(spec) + end + +end + diff --git a/lib/rubygems/indexer/master_index_builder.rb b/lib/rubygems/indexer/master_index_builder.rb index dbe02370a9..669ea5a1df 100644 --- a/lib/rubygems/indexer/master_index_builder.rb +++ b/lib/rubygems/indexer/master_index_builder.rb @@ -1,6 +1,8 @@ require 'rubygems/indexer' +## # Construct the master Gem index file. + class Gem::Indexer::MasterIndexBuilder < Gem::Indexer::AbstractIndexBuilder def start_index @@ -10,6 +12,7 @@ class Gem::Indexer::MasterIndexBuilder < Gem::Indexer::AbstractIndexBuilder def end_index super + @file.puts "--- !ruby/object:#{@index.class}" @file.puts "gems:" @@ -28,11 +31,9 @@ class Gem::Indexer::MasterIndexBuilder < Gem::Indexer::AbstractIndexBuilder index_file_name = File.join @directory, @filename compress index_file_name, "Z" - compressed_file_name = "#{index_file_name}.Z" - - paranoid index_file_name, compressed_file_name + paranoid index_file_name, "#{index_file_name}.Z" - @files << compressed_file_name + @files << "#{@filename}.Z" end def add(spec) @@ -41,12 +42,12 @@ class Gem::Indexer::MasterIndexBuilder < Gem::Indexer::AbstractIndexBuilder private - def paranoid(fn, compressed_fn) - data = File.open(fn, 'rb') do |fp| fp.read end - compressed_data = File.open(compressed_fn, 'rb') do |fp| fp.read end + def paranoid(path, compressed_path) + data = Gem.read_binary path + compressed_data = Gem.read_binary compressed_path if data != unzip(compressed_data) then - fail "Compressed file #{compressed_fn} does not match uncompressed file #{fn}" + raise "Compressed file #{compressed_path} does not match uncompressed file #{path}" end end diff --git a/lib/rubygems/indexer/quick_index_builder.rb b/lib/rubygems/indexer/quick_index_builder.rb index 23c7ca696b..dc36179dc5 100644 --- a/lib/rubygems/indexer/quick_index_builder.rb +++ b/lib/rubygems/indexer/quick_index_builder.rb @@ -1,7 +1,9 @@ require 'rubygems/indexer' +## # Construct a quick index file and all of the individual specs to support # incremental loading. + class Gem::Indexer::QuickIndexBuilder < Gem::Indexer::AbstractIndexBuilder def initialize(filename, directory) @@ -13,12 +15,12 @@ class Gem::Indexer::QuickIndexBuilder < Gem::Indexer::AbstractIndexBuilder def cleanup super - quick_index_file = File.join(@directory, @filename) + quick_index_file = File.join @directory, @filename compress quick_index_file # the complete quick index is in a directory, so move it as a whole - @files.delete quick_index_file - @files << @directory + @files.delete 'index' + @files << 'quick' end def add(spec) -- cgit v1.2.3