ruby-changes:18726
From: ryan <ko1@a...>
Date: Tue, 1 Feb 2011 12:14:35 +0900 (JST)
Subject: [ruby-changes:18726] Ruby:r30752 (trunk): Import rubygems 1.5.0 (released version @ 1fb59d0)
ryan 2011-02-01 12:11:34 +0900 (Tue, 01 Feb 2011) New Revision: 30752 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30752 Log: Import rubygems 1.5.0 (released version @ 1fb59d0) Modified files: trunk/ChangeLog trunk/lib/rubygems/builder.rb trunk/lib/rubygems/commands/setup_command.rb trunk/lib/rubygems/commands/unpack_command.rb trunk/lib/rubygems/format.rb trunk/lib/rubygems/installer.rb trunk/lib/rubygems/package/tar_input.rb trunk/lib/rubygems/package/tar_reader/entry.rb trunk/lib/rubygems/package.rb trunk/lib/rubygems/package_task.rb trunk/lib/rubygems/user_interaction.rb trunk/test/rubygems/test_gem_commands_unpack_command.rb trunk/test/rubygems/test_gem_format.rb trunk/test/rubygems/test_gem_package_tar_input.rb trunk/test/rubygems/test_gem_package_tar_reader_entry.rb trunk/test/rubygems/test_gem_package_task.rb trunk/test/rubygems/test_gem_security.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 30751) +++ ChangeLog (revision 30752) @@ -1,3 +1,8 @@ +Tue Feb 1 11:03:47 2011 Ryan Davis <ryan@l...> + + * lib/rubygems*: Import rubygems 1.5.0 (released version @ 1fb59d0) + * test/rubygems: Ditto + Tue Feb 1 08:01:39 2011 Nobuyoshi Nakada <nobu@r...> * ext/io/console/console.c (console_set_winsize): new method to set Index: lib/rubygems/user_interaction.rb =================================================================== --- lib/rubygems/user_interaction.rb (revision 30751) +++ lib/rubygems/user_interaction.rb (revision 30752) @@ -530,9 +530,21 @@ ## # SilentUI is a UI choice that is absolutely silent. -class Gem::SilentUI - def method_missing(sym, *args, &block) - self +class Gem::SilentUI < Gem::StreamUI + + def initialize + + reader, writer = nil, nil + + if Gem.win_platform? + reader = File.open('nul', 'r') + writer = File.open('nul', 'w') + else + reader = File.open('/dev/null', 'r') + writer = File.open('/dev/null', 'w') + end + + super reader, writer, writer end end Index: lib/rubygems/builder.rb =================================================================== --- lib/rubygems/builder.rb (revision 30751) +++ lib/rubygems/builder.rb (revision 30752) @@ -10,13 +10,9 @@ # See LICENSE.txt for permissions. #++ +require 'rubygems' require 'rubygems/user_interaction' -begin - require 'psych' -rescue LoadError -end - Gem.load_yaml require 'rubygems/package' Index: lib/rubygems/format.rb =================================================================== --- lib/rubygems/format.rb (revision 30751) +++ lib/rubygems/format.rb (revision 30752) @@ -47,8 +47,13 @@ Gem::OldFormat.from_file_by_path file_path else - open file_path, Gem.binary_mode do |io| - from_io io, file_path, security_policy + begin + open file_path, Gem.binary_mode do |io| + from_io io, file_path, security_policy + end + rescue Gem::Package::TarInvalidError => e + message = "corrupt gem (#{e.class}: #{e.message})" + raise Gem::Package::FormatError.new(message, file_path) end end end Index: lib/rubygems/package_task.rb =================================================================== --- lib/rubygems/package_task.rb (revision 30751) +++ lib/rubygems/package_task.rb (revision 30752) @@ -92,7 +92,7 @@ # Initialization tasks without the "yield self" or define operations. def init(gem) - super gem.name, gem.version + super gem.full_name, :noversion @gem_spec = gem @package_files += gem_spec.files if gem_spec.files end @@ -120,11 +120,13 @@ chdir(gem_dir) do when_writing "Creating #{gem_spec.file_name}" do Gem::Builder.new(gem_spec).build - verbose(true) { - mv gem_file, ".." - } + verbose trace do + mv gem_file, '..' + end end end end end + end + Index: lib/rubygems/package/tar_input.rb =================================================================== --- lib/rubygems/package/tar_input.rb (revision 30751) +++ lib/rubygems/package/tar_input.rb (revision 30752) @@ -117,7 +117,11 @@ @tarreader.rewind @fileops = Gem::FileOperations.new - raise Gem::Package::FormatError, "No metadata found!" unless has_meta + unless has_meta then + path = io.path if io.respond_to? :path + error = Gem::Package::FormatError.new 'no metadata found', path + raise error + end end def close Index: lib/rubygems/package/tar_reader/entry.rb =================================================================== --- lib/rubygems/package/tar_reader/entry.rb (revision 30751) +++ lib/rubygems/package/tar_reader/entry.rb (revision 30752) @@ -73,6 +73,10 @@ else @header.name end + rescue ArgumentError => e + raise unless e.message == 'string contains null byte' + raise Gem::Package::TarInvalidError, + 'tar is corrupt, name contains null byte' end ## Index: lib/rubygems/package.rb =================================================================== --- lib/rubygems/package.rb (revision 30751) +++ lib/rubygems/package.rb (revision 30752) @@ -45,8 +45,24 @@ class ClosedIO < Error; end class BadCheckSum < Error; end class TooLongFileName < Error; end - class FormatError < Error; end + class FormatError < Error + attr_reader :path + def initialize message, path = nil + @path = path + + message << " in #{path}" if path + + super message + end + + end + + ## + # Raised when a tar file is corrupt + + class TarInvalidError < Error; end + def self.open(io, mode = "r", signer = nil, &block) tar_type = case mode when 'r' then TarInput Index: lib/rubygems/installer.rb =================================================================== --- lib/rubygems/installer.rb (revision 30751) +++ lib/rubygems/installer.rb (revision 30752) @@ -395,19 +395,19 @@ :force => false, :install_dir => Gem.dir, :source_index => Gem.source_index, - }.merge @options + }.merge options - @env_shebang = @options[:env_shebang] - @force = @options[:force] - gem_home = @options[:install_dir] + @env_shebang = options[:env_shebang] + @force = options[:force] + gem_home = options[:install_dir] @gem_home = File.expand_path(gem_home) - @ignore_dependencies = @options[:ignore_dependencies] - @format_executable = @options[:format_executable] - @security_policy = @options[:security_policy] - @wrappers = @options[:wrappers] - @bin_dir = @options[:bin_dir] - @development = @options[:development] - @source_index = @options[:source_index] + @ignore_dependencies = options[:ignore_dependencies] + @format_executable = options[:format_executable] + @security_policy = options[:security_policy] + @wrappers = options[:wrappers] + @bin_dir = options[:bin_dir] + @development = options[:development] + @source_index = options[:source_index] end def load_gem_file @@ -508,8 +508,8 @@ rescue TypeError # extension == nil @gem_dir end - + begin Dir.chdir extension_dir do results = builder.build(extension, @gem_dir, dest_path, results) Index: lib/rubygems/commands/unpack_command.rb =================================================================== --- lib/rubygems/commands/unpack_command.rb (revision 30751) +++ lib/rubygems/commands/unpack_command.rb (revision 30752) @@ -72,6 +72,22 @@ end ## + # + # Find cached filename in Gem.path. Returns nil if the file cannot be found. + # + #-- + # TODO: see comments in get_path() about general service. + + def find_in_cache(filename) + Gem.path.each do |gem_dir| + this_path = File.join gem_dir, 'cache', filename + return this_path if File.exist? this_path + end + + return nil + end + + ## # Return the full path to the cached gem file matching the given # name and version requirement. Returns 'nil' if no match. # @@ -101,14 +117,10 @@ # We expect to find (basename).gem in the 'cache' directory. Furthermore, # the name match must be exact (ignoring case). - filename = selected.file_name - path = nil + + path = find_in_cache(selected.file_name) + return download(dependency) unless path - Gem.path.find do |gem_dir| - path = File.join gem_dir, 'cache', filename - File.exist? path - end - path end Index: lib/rubygems/commands/setup_command.rb =================================================================== --- lib/rubygems/commands/setup_command.rb (revision 30751) +++ lib/rubygems/commands/setup_command.rb (revision 30752) @@ -342,8 +342,10 @@ require 'rdoc/rdoc' args << '--quiet' - args << '--main' << 'README' - args << '.' << 'README' << 'LICENSE.txt' << 'GPL.txt' + args << '--main' << 'README.rdoc' + args << '.' + args << 'README.rdoc' << 'UPGRADING.rdoc' + args << 'LICENSE.txt' << 'GPL.txt' << 'History.txt' r = RDoc::RDoc.new r.document args Index: test/rubygems/test_gem_package_tar_reader_entry.rb =================================================================== --- test/rubygems/test_gem_package_tar_reader_entry.rb (revision 30751) +++ test/rubygems/test_gem_package_tar_reader_entry.rb (revision 30752) @@ -67,6 +67,16 @@ assert_equal 'lib/foo', @entry.full_name end + def test_full_name_null + @entry.header.prefix << "\000" + + e = assert_raises Gem::Package::TarInvalidError do + @entry.full_name + end + + assert_equal 'tar is corrupt, name contains null byte', e.message + end + def test_getc assert_equal ?a, @entry.getc end Index: test/rubygems/test_gem_format.rb =================================================================== --- test/rubygems/test_gem_format.rb (revision 30751) +++ test/rubygems/test_gem_format.rb (revision 30752) @@ -4,11 +4,11 @@ # File a patch instead and assign it to Ryan Davis or Eric Hodel. ###################################################################### -require 'rubygems/test_case' -require "test/rubygems/simple_gem" +require 'rubygems/package/tar_test_case' +require 'test/rubygems/simple_gem' require 'rubygems/format' -class TestGemFormat < Gem::TestCase +class TestGemFormat < Gem::Package::TarTestCase def setup super @@ -16,6 +16,7 @@ @simple_gem = SIMPLE_GEM end + # HACK this test should do less def test_class_from_file_by_path util_make_gems @@ -34,6 +35,23 @@ end end + def test_class_from_file_by_path_corrupt + Tempfile.open 'corrupt' do |io| + data = Gem.gzip 'a' * 10 + io.write tar_file_header('metadata.gz', "\000x", 0644, data.length) + io.write data + io.rewind + + e = assert_raises Gem::Package::FormatError do + Gem::Format.from_file_by_path io.path + end + + sub_message = 'Gem::Package::TarInvalidError: tar is corrupt, name contains null byte' + assert_equal "corrupt gem (#{sub_message}) in #{io.path}", e.message + assert_equal io.path, e.path + end + end + def test_class_from_file_by_path_empty util_make_gems @@ -55,21 +73,21 @@ Gem::Format.from_io(StringIO.new(@simple_gem.upcase)) end - assert_equal 'No metadata found!', e.message + assert_equal 'no metadata found', e.message e = assert_raises Gem::Package::FormatError do # Totally bogus input Gem::Format.from_io(StringIO.new(@simple_gem.reverse)) end - assert_equal 'No metadata found!', e.message + assert_equal 'no metadata found', e.message e = assert_raises Gem::Package::FormatError do # This was intentionally screws up YAML parsing. Gem::Format.from_io(StringIO.new(@simple_gem.gsub(/:/, "boom"))) end - assert_equal 'No metadata found!', e.message + assert_equal 'no metadata found', e.message end end Index: test/rubygems/test_gem_package_task.rb =================================================================== --- test/rubygems/test_gem_package_task.rb (revision 30751) +++ test/rubygems/test_gem_package_task.rb (revision 30752) @@ -48,5 +48,18 @@ assert_equal ["x", "y"], pkg.package_files end + def test_package_dir_path + gem = Gem::Specification.new do |g| + g.name = 'nokogiri' + g.version = '1.5.0' + g.platform = 'java' + end + + pkg = Gem::PackageTask.new gem + pkg.define + + assert_equal 'pkg/nokogiri-1.5.0-java', pkg.package_dir_path + end + end Index: test/rubygems/test_gem_package_tar_input.rb =================================================================== --- test/rubygems/test_gem_package_tar_input.rb (revision 30751) +++ test/rubygems/test_gem_package_tar_input.rb (revision 30752) @@ -59,7 +59,24 @@ @entry_contents = %w[0123456789 01234] end - def test_each_works + def test_initialize_no_metadata_file + Tempfile.open 'no_meta' do |io| + io.write tar_file_header('a', '', 0644, 1) + io.write 'a' + io.rewind + + e = assert_raises Gem::Package::FormatError do + open io.path, Gem.binary_mode do |file| + Gem::Package::TarInput.open file do end + end + end + + assert_equal "no metadata found in #{io.path}", e.message + assert_equal io.path, e.path + end + end + + def test_each open @file, 'rb' do |io| Gem::Package::TarInput.open io do |tar_input| count = 0 @@ -79,7 +96,7 @@ end end - def test_extract_entry_works + def test_extract_entry open @file, 'rb' do |io| Gem::Package::TarInput.open io do |tar_input| assert_equal @spec, tar_input.metadata Index: test/rubygems/test_gem_commands_unpack_command.rb =================================================================== --- test/rubygems/test_gem_commands_unpack_command.rb (revision 30751) +++ test/rubygems/test_gem_commands_unpack_command.rb (revision 30752) @@ -17,6 +17,46 @@ end end + def test_find_in_cache + util_make_gems + + assert_equal( + @cmd.find_in_cache(@a1.file_name), + File.join(@gemhome, 'cache', @a1.file_name), + 'found a-1.gem in the cache' + ) + end + + def test_get_path + util_make_gems + util_setup_fake_fetcher + util_setup_spec_fetcher @a1 + + a1_data = nil + + open File.join(@gemhome, 'cache', @a1.file_name), 'rb' do |fp| + a1_data = fp.read + end + + Gem::RemoteFetcher.fetcher.data['http://gems.example.com/gems/a-1.gem'] = + a1_data + + dep = Gem::Dependency.new(@a1.name, @a1.version) + assert_equal( + @cmd.get_path(dep), + File.join(@gemhome, 'cache', @a1.file_name), + 'fetches a-1 and returns the cache path' + ) + + FileUtils.rm File.join(@gemhome, 'cache', @a1.file_name) + + assert_equal( + @cmd.get_path(dep), + File.join(@gemhome, 'cache', @a1.file_name), + 'when removed from cache, refetches a-1' + ) + end + def test_execute util_make_gems Index: test/rubygems/test_gem_security.rb =================================================================== --- test/rubygems/test_gem_security.rb (revision 30751) +++ test/rubygems/test_gem_security.rb (revision 30752) @@ -93,4 +93,3 @@ end end if defined?(OpenSSL) - -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/