From ec84bfc9e3d11a3b1dbebcaf4d1ddf1357307513 Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 1 Feb 2011 03:11:34 +0000 Subject: Import rubygems 1.5.0 (released version @ 1fb59d0) git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems/builder.rb | 6 +----- lib/rubygems/commands/setup_command.rb | 6 ++++-- lib/rubygems/commands/unpack_command.rb | 26 +++++++++++++++++++------- lib/rubygems/format.rb | 9 +++++++-- lib/rubygems/installer.rb | 24 ++++++++++++------------ lib/rubygems/package.rb | 18 +++++++++++++++++- lib/rubygems/package/tar_input.rb | 6 +++++- lib/rubygems/package/tar_reader/entry.rb | 4 ++++ lib/rubygems/package_task.rb | 10 ++++++---- lib/rubygems/user_interaction.rb | 18 +++++++++++++++--- 10 files changed, 90 insertions(+), 37 deletions(-) (limited to 'lib/rubygems') diff --git a/lib/rubygems/builder.rb b/lib/rubygems/builder.rb index b5d596b1f3..c07369f256 100644 --- a/lib/rubygems/builder.rb +++ b/lib/rubygems/builder.rb @@ -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' diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index b7fb62cf53..f40733a3ed 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -342,8 +342,10 @@ abort "#{deprecation_message}" 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 diff --git a/lib/rubygems/commands/unpack_command.rb b/lib/rubygems/commands/unpack_command.rb index 5e0bc830f2..ac1d376106 100644 --- a/lib/rubygems/commands/unpack_command.rb +++ b/lib/rubygems/commands/unpack_command.rb @@ -71,6 +71,22 @@ class Gem::Commands::UnpackCommand < Gem::Command end 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,13 +117,9 @@ class Gem::Commands::UnpackCommand < Gem::Command # 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 - - Gem.path.find do |gem_dir| - path = File.join gem_dir, 'cache', filename - File.exist? path - end + + path = find_in_cache(selected.file_name) + return download(dependency) unless path path end diff --git a/lib/rubygems/format.rb b/lib/rubygems/format.rb index 3b38a3a017..95388b4e51 100644 --- a/lib/rubygems/format.rb +++ b/lib/rubygems/format.rb @@ -47,8 +47,13 @@ class Gem::Format 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 diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 09d260dfb8..5c7c57685b 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -395,19 +395,19 @@ class Gem::Installer :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,7 +508,7 @@ TEXT rescue TypeError # extension == nil @gem_dir end - + begin Dir.chdir extension_dir do diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index 0fd27a0108..3a50ca118e 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -45,7 +45,23 @@ module Gem::Package 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 diff --git a/lib/rubygems/package/tar_input.rb b/lib/rubygems/package/tar_input.rb index 587d79c493..401df80a83 100644 --- a/lib/rubygems/package/tar_input.rb +++ b/lib/rubygems/package/tar_input.rb @@ -117,7 +117,11 @@ class Gem::Package::TarInput @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 diff --git a/lib/rubygems/package/tar_reader/entry.rb b/lib/rubygems/package/tar_reader/entry.rb index d5c624f3d5..c70248f159 100644 --- a/lib/rubygems/package/tar_reader/entry.rb +++ b/lib/rubygems/package/tar_reader/entry.rb @@ -73,6 +73,10 @@ class Gem::Package::TarReader::Entry 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 ## diff --git a/lib/rubygems/package_task.rb b/lib/rubygems/package_task.rb index 2e9c89d834..ae4f2019ae 100644 --- a/lib/rubygems/package_task.rb +++ b/lib/rubygems/package_task.rb @@ -92,7 +92,7 @@ class Gem::PackageTask < Rake::PackageTask # 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 @@ class Gem::PackageTask < Rake::PackageTask 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 + diff --git a/lib/rubygems/user_interaction.rb b/lib/rubygems/user_interaction.rb index 9822a23c35..ff5800c116 100644 --- a/lib/rubygems/user_interaction.rb +++ b/lib/rubygems/user_interaction.rb @@ -530,9 +530,21 @@ end ## # 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 -- cgit v1.2.3