From 8b424513fd43c398aaeea5dede8bbc5c51602773 Mon Sep 17 00:00:00 2001 From: drbrain Date: Thu, 26 Jun 2008 02:06:00 +0000 Subject: Upgrade to RubyGems 1.2.0 r1824. Incorporates [ruby-core:17353]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems/commands/install_command.rb | 6 +- lib/rubygems/config_file.rb | 22 ++++++- lib/rubygems/defaults.rb | 4 +- lib/rubygems/dependency_installer.rb | 5 +- lib/rubygems/ext/rake_builder.rb | 2 +- lib/rubygems/indexer.rb | 24 ++++--- lib/rubygems/install_update_options.rb | 7 +++ lib/rubygems/installer.rb | 28 ++++++++- lib/rubygems/remote_fetcher.rb | 104 ++++++++++++++++--------------- lib/rubygems/rubygems_version.rb | 2 +- lib/rubygems/spec_fetcher.rb | 32 ++++------ lib/rubygems/specification.rb | 27 +++++--- lib/rubygems/test_utilities.rb | 9 ++- lib/rubygems/uninstaller.rb | 16 ++--- 14 files changed, 180 insertions(+), 108 deletions(-) (limited to 'lib/rubygems') diff --git a/lib/rubygems/commands/install_command.rb b/lib/rubygems/commands/install_command.rb index dad19380ea..923d578a15 100644 --- a/lib/rubygems/commands/install_command.rb +++ b/lib/rubygems/commands/install_command.rb @@ -50,11 +50,7 @@ class Gem::Commands::InstallCommand < Gem::Command installed_gems = [] - if options[:install_dir].nil? and RUBY_VERSION > '1.9' then - ENV.delete 'GEM_PATH' - else - ENV['GEM_PATH'] = options[:install_dir] # HACK what does this do? - end + ENV.delete 'GEM_PATH' if options[:install_dir].nil? and RUBY_VERSION > '1.9' install_options = { :env_shebang => options[:env_shebang], diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb index 8cea513790..c093c31a1b 100644 --- a/lib/rubygems/config_file.rb +++ b/lib/rubygems/config_file.rb @@ -18,6 +18,18 @@ class Gem::ConfigFile DEFAULT_VERBOSITY = true DEFAULT_UPDATE_SOURCES = true + ## + # For Ruby packagers to set configuration defaults. Set in + # rubygems/defaults/operating_system.rb + + OPERATING_SYSTEM_DEFAULTS = {} + + ## + # For Ruby implementers to set configuration defaults. Set in + # rubygems/defaults/#{RUBY_ENGINE}.rb + + PLATFORM_DEFAULTS = {} + system_config_path = begin require 'Win32API' @@ -98,8 +110,14 @@ class Gem::ConfigFile @verbose = DEFAULT_VERBOSITY @update_sources = DEFAULT_UPDATE_SOURCES - @hash = load_file(SYSTEM_WIDE_CONFIG_FILE) - @hash.merge!(load_file(config_file_name.dup.untaint)) + operating_system_config = Marshal.load Marshal.dump(OPERATING_SYSTEM_DEFAULTS) + platform_config = Marshal.load Marshal.dump(PLATFORM_DEFAULTS) + system_config = load_file SYSTEM_WIDE_CONFIG_FILE + user_config = load_file config_file_name.dup.untaint + + @hash = operating_system_config.merge platform_config + @hash = @hash.merge system_config + @hash = @hash.merge user_config # HACK these override command-line args, which is bad @backtrace = @hash[:backtrace] if @hash.key? :backtrace diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb index 914b9f777f..8bb9776575 100644 --- a/lib/rubygems/defaults.rb +++ b/lib/rubygems/defaults.rb @@ -19,9 +19,9 @@ module Gem end end - # Default gem path. + # Default gem load path. def self.default_path - default_dir + [File.join(ENV['HOME'], '.gem'), default_dir] end # Deduce Ruby's --program-prefix and --program-suffix from its install name. diff --git a/lib/rubygems/dependency_installer.rb b/lib/rubygems/dependency_installer.rb index 8636599fbc..8406844e79 100644 --- a/lib/rubygems/dependency_installer.rb +++ b/lib/rubygems/dependency_installer.rb @@ -133,7 +133,9 @@ class Gem::DependencyInstaller deps.each do |dep| results = find_gems_with_sources(dep).reverse - results.reject! do + results.reject! do |dep_spec,| + to_do.push dep_spec + @source_index.any? do |_, installed_spec| dep.name == installed_spec.name and dep.version_requirements.satisfied_by? installed_spec.version @@ -144,7 +146,6 @@ class Gem::DependencyInstaller next if seen[dep_spec.name] @specs_and_sources << [dep_spec, source_uri] dependency_list.add dep_spec - to_do.push dep_spec end end end diff --git a/lib/rubygems/ext/rake_builder.rb b/lib/rubygems/ext/rake_builder.rb index 3772f6a00f..0c64e611a0 100644 --- a/lib/rubygems/ext/rake_builder.rb +++ b/lib/rubygems/ext/rake_builder.rb @@ -16,7 +16,7 @@ class Gem::Ext::RakeBuilder < Gem::Ext::Builder end cmd = ENV['rake'] || 'rake' - cmd << " RUBYARCHDIR=#{dest_path} RUBYLIBDIR=#{dest_path}" + cmd += " RUBYARCHDIR=#{dest_path} RUBYLIBDIR=#{dest_path}" # ENV is frozen run cmd, results diff --git a/lib/rubygems/indexer.rb b/lib/rubygems/indexer.rb index b45931a91d..e2dd57d3fe 100644 --- a/lib/rubygems/indexer.rb +++ b/lib/rubygems/indexer.rb @@ -116,7 +116,7 @@ class Gem::Indexer open @specs_index, 'wb' do |io| specs = index.sort.map do |_, spec| platform = spec.original_platform - platform = Gem::Platform::RUBY if platform.nil? + platform = Gem::Platform::RUBY if platform.nil? or platform.empty? [spec.name, spec.version, platform] end @@ -129,7 +129,9 @@ class Gem::Indexer open @latest_specs_index, 'wb' do |io| specs = index.latest_specs.sort.map do |spec| - [spec.name, spec.version, spec.original_platform] + platform = spec.original_platform + platform = Gem::Platform::RUBY if platform.nil? or platform.empty? + [spec.name, spec.version, platform] end specs = compact_specs specs @@ -283,10 +285,7 @@ class Gem::Indexer # Builds and installs indexicies. def generate_index - FileUtils.rm_rf @directory - FileUtils.mkdir_p @directory, :mode => 0700 - FileUtils.mkdir_p @quick_marshal_dir - + make_temp_directories index = collect_specs build_indicies index install_indicies @@ -317,10 +316,20 @@ class Gem::Indexer dst_name = File.join @dest_directory, file FileUtils.rm_rf dst_name, :verbose => verbose - FileUtils.mv src_name, @dest_directory, :verbose => verbose + FileUtils.mv src_name, @dest_directory, :verbose => verbose, + :force => true end end + ## + # Make directories for index generation + + def make_temp_directories + FileUtils.rm_rf @directory + FileUtils.mkdir_p @directory, :mode => 0700 + FileUtils.mkdir_p @quick_marshal_dir + end + ## # Ensure +path+ and path with +extension+ are identical. @@ -343,6 +352,7 @@ class Gem::Indexer spec.description = sanitize_string(spec.description) spec.post_install_message = sanitize_string(spec.post_install_message) spec.authors = spec.authors.collect { |a| sanitize_string(a) } + spec end diff --git a/lib/rubygems/install_update_options.rb b/lib/rubygems/install_update_options.rb index 5202c105db..dd35acb176 100644 --- a/lib/rubygems/install_update_options.rb +++ b/lib/rubygems/install_update_options.rb @@ -90,6 +90,13 @@ module Gem::InstallUpdateOptions options[:format_executable] = value end + add_option(:"Install/Update", '--[no-]user-install', + 'Install in user\'s home directory instead', + 'of GEM_HOME. Defaults to using home directory', + 'only if GEM_HOME is not writable.') do |value, options| + options[:user_install] = value + end + add_option(:"Install/Update", "--development", "Install any additional development", "dependencies") do |value, options| diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index ae699a90a0..5e2e8e0f42 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -85,6 +85,32 @@ class Gem::Installer raise Gem::InstallError, "invalid gem format for #{@gem}" end + if not File.writable? @gem_home or + # TODO: Shouldn't have to test for existence of bindir; tests need it. + (@gem_home.to_s == Gem.dir and File.exist? Gem.bindir and + not File.writable? Gem.bindir) + if options[:user_install] == false # You explicitly don't want to use ~ + raise Gem::FilePermissionError, @gem_home + elsif options[:user_install].nil? + say "Warning: falling back to user-level install since #{@gem_home} and #{@bin_dir} aren't both writable." + end + options[:user_install] = true + end + + if options[:user_install] + @gem_home = File.join(ENV['HOME'], '.gem') + + user_bin_dir = File.join(@gem_home, 'gems', 'bin') + if !ENV['PATH'].split(':').include?(user_bin_dir) + say "You don't have #{user_bin_dir} in your PATH." + say "You won't be able to run gem-installed executables until you add it." + end + + Dir.mkdir @gem_home if ! File.directory? @gem_home + # If it's still not writable, you've got issues. + raise Gem::FilePermissionError, @gem_home if ! File.writable? @gem_home + end + @spec = @format.spec @gem_dir = File.join(@gem_home, "gems", @spec.full_name).untaint @@ -132,7 +158,6 @@ class Gem::Installer end FileUtils.mkdir_p @gem_home unless File.directory? @gem_home - raise Gem::FilePermissionError, @gem_home unless File.writable? @gem_home Gem.ensure_gem_subdirectories @gem_home @@ -206,6 +231,7 @@ class Gem::Installer file_name = File.join @gem_home, 'specifications', "#{@spec.full_name}.gemspec" + file_name.untaint File.open(file_name, "w") do |file| diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb index 93252fe83a..3c747f1d65 100644 --- a/lib/rubygems/remote_fetcher.rb +++ b/lib/rubygems/remote_fetcher.rb @@ -1,5 +1,6 @@ require 'net/http' require 'stringio' +require 'time' require 'uri' require 'rubygems' @@ -74,7 +75,12 @@ class Gem::RemoteFetcher # always replaced. def download(spec, source_uri, install_dir = Gem.dir) - cache_dir = File.join install_dir, 'cache' + if File.writable?(install_dir) + cache_dir = File.join install_dir, 'cache' + else + cache_dir = File.join(ENV['HOME'], '.gem', 'cache') + end + gem_file_name = "#{spec.full_name}.gem" local_gem_path = File.join cache_dir, gem_file_name @@ -132,49 +138,27 @@ class Gem::RemoteFetcher ## # Downloads +uri+ and returns it as a String. - def fetch_path(uri) - open_uri_or_path(uri) do |input| - input.read - end + def fetch_path(uri, mtime = nil, head = false) + data = open_uri_or_path(uri, mtime, head) + data = Gem.gunzip data if uri.to_s =~ /gz$/ and not head + data rescue FetchError raise rescue Timeout::Error raise FetchError.new('timed out', uri) rescue IOError, SocketError, SystemCallError => e raise FetchError.new("#{e.class}: #{e}", uri) - rescue => e - raise FetchError.new("#{e.class}: #{e}", uri) end ## # Returns the size of +uri+ in bytes. - def fetch_size(uri) - return File.size(get_file_uri_path(uri)) if file_uri? uri - - uri = URI.parse uri unless URI::Generic === uri - - raise ArgumentError, 'uri is not an HTTP URI' unless URI::HTTP === uri - - response = request uri, Net::HTTP::Head + def fetch_size(uri) # TODO: phase this out + response = fetch_path(uri, nil, true) - if response.code !~ /^2/ then - raise FetchError.new("bad response #{response.message} #{response.code}", uri) - end - - if response['content-length'] then - return response['content-length'].to_i - else - response = http.get uri.request_uri - return response.body.size - end - - rescue SocketError, SystemCallError, Timeout::Error => e - raise FetchError.new("#{e.message} (#{e.class})\n\tfetching size", uri) + response['content-length'].to_i end - private - def escape(str) return unless str URI.escape(str) @@ -245,24 +229,26 @@ class Gem::RemoteFetcher # Read the data from the (source based) URI, but if it is a file:// URI, # read from the filesystem instead. - def open_uri_or_path(uri, depth = 0, &block) - if file_uri?(uri) - open(get_file_uri_path(uri), &block) - else - uri = URI.parse uri unless URI::Generic === uri + def open_uri_or_path(uri, last_modified = nil, head = false, depth = 0) + raise "block is dead" if block_given? - response = request uri + return open(get_file_uri_path(uri)) if file_uri? uri - case response - when Net::HTTPOK then - block.call(StringIO.new(response.body)) if block - when Net::HTTPRedirection then - raise FetchError.new('too many redirects', uri) if depth > 10 + uri = URI.parse uri unless URI::Generic === uri + raise ArgumentError, 'uri is not an HTTP URI' unless URI::HTTP === uri - open_uri_or_path(response['Location'], depth + 1, &block) - else - raise FetchError.new("bad response #{response.message} #{response.code}", uri) - end + fetch_type = head ? Net::HTTP::Head : Net::HTTP::Get + response = request uri, fetch_type, last_modified + + case response + when Net::HTTPOK then + head ? response : response.body + when Net::HTTPRedirection then + raise FetchError.new('too many redirects', uri) if depth > 10 + + open_uri_or_path(response['Location'], last_modified, head, depth + 1) + else + raise FetchError.new("bad response #{response.message} #{response.code}", uri) end end @@ -271,7 +257,7 @@ class Gem::RemoteFetcher # a Net::HTTP response object. request maintains a table of persistent # connections to reduce connect overhead. - def request(uri, request_class = Net::HTTP::Get) + def request(uri, request_class, last_modified = nil) request = request_class.new uri.request_uri unless uri.nil? || uri.user.nil? || uri.user.empty? then @@ -287,9 +273,14 @@ class Gem::RemoteFetcher request.add_field 'Connection', 'keep-alive' request.add_field 'Keep-Alive', '30' + if last_modified then + request.add_field 'If-Modified-Since', last_modified.rfc2822 + end + connection = connection_for uri retried = false + bad_response = false # HACK work around EOFError bug in Net::HTTP # NOTE Errno::ECONNABORTED raised a lot on Windows, and make impossible @@ -299,6 +290,13 @@ class Gem::RemoteFetcher response = connection.request request say "#{request.method} #{response.code} #{response.message}: #{uri}" if Gem.configuration.really_verbose + rescue Net::HTTPBadResponse + reset connection + + raise FetchError.new('too many bad responses', uri) if bad_response + + bad_response = true + retry rescue EOFError, Errno::ECONNABORTED, Errno::ECONNRESET requests = @requests[connection.object_id] say "connection reset after #{requests} requests, retrying" if @@ -306,10 +304,8 @@ class Gem::RemoteFetcher raise FetchError.new('too many connection resets', uri) if retried - @requests.delete connection.object_id + reset connection - connection.finish - connection.start retried = true retry end @@ -317,6 +313,16 @@ class Gem::RemoteFetcher response end + ## + # Resets HTTP connection +connection+. + + def reset(connection) + @requests.delete connection.object_id + + connection.finish + connection.start + end + ## # Checks if the provided string is a file:// URI. diff --git a/lib/rubygems/rubygems_version.rb b/lib/rubygems/rubygems_version.rb index 453f9b57b6..d393e57a09 100644 --- a/lib/rubygems/rubygems_version.rb +++ b/lib/rubygems/rubygems_version.rb @@ -2,5 +2,5 @@ # This file is auto-generated by build scripts. # See: rake update_version module Gem - RubyGemsVersion = '1.1.1' + RubyGemsVersion = '1.2.0.1824' end diff --git a/lib/rubygems/spec_fetcher.rb b/lib/rubygems/spec_fetcher.rb index 29db889af5..66b4ee36c7 100644 --- a/lib/rubygems/spec_fetcher.rb +++ b/lib/rubygems/spec_fetcher.rb @@ -183,29 +183,23 @@ class Gem::SpecFetcher end def load_specs(source_uri, file) - file_name = "#{file}.#{Gem.marshal_version}.gz" - - spec_path = source_uri + file_name - - cache_dir = cache_dir spec_path - - local_file = File.join(cache_dir, file_name).chomp '.gz' + file_name = "#{file}.#{Gem.marshal_version}" + spec_path = source_uri + "#{file_name}.gz" + cache_dir = cache_dir spec_path + local_file = File.join(cache_dir, file_name) + loaded = false if File.exist? local_file then - local_size = File.stat(local_file).size - - remote_file = spec_path.dup - remote_file.path = remote_file.path.chomp '.gz' - remote_size = @fetcher.fetch_size remote_file - - spec_dump = Gem.read_binary local_file if remote_size == local_size - end + spec_dump = @fetcher.fetch_path spec_path, File.mtime(local_file) - unless spec_dump then + if spec_dump.empty? then + spec_dump = Gem.read_binary local_file + else + loaded = true + end + else + spec_dump = @fetcher.fetch_path spec_path loaded = true - - spec_dump_gz = @fetcher.fetch_path spec_path - spec_dump = Gem.gunzip spec_dump_gz end specs = Marshal.load spec_dump diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 0642a4f3e0..f3f38e5033 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -60,8 +60,10 @@ module Gem # changes. #-- # When updating this number, be sure to also update #to_ruby. + # + # NOTE RubyGems < 1.2 cannot load specification versions > 2. - CURRENT_SPECIFICATION_VERSION = 3 + CURRENT_SPECIFICATION_VERSION = 2 ## # An informal list of changes to the specification. The highest-valued @@ -77,13 +79,10 @@ module Gem 'Added "required_rubygems_version"', 'Now forward-compatible with future versions', ], - 3 => [ - 'Added dependency types', - ], } # :stopdoc: - MARSHAL_FIELDS = { -1 => 16, 1 => 16, 2 => 16, 3 => 16 } + MARSHAL_FIELDS = { -1 => 16, 1 => 16, 2 => 16 } now = Time.at(Time.now.to_i) TODAY = now - ((now.to_i + now.gmt_offset) % 86400) @@ -248,10 +247,12 @@ module Gem } end + ## # Dump only crucial instance variables. - # + #-- # MAINTAIN ORDER! - def _dump(limit) # :nodoc: + + def _dump(limit) Marshal.dump [ @rubygems_version, @specification_version, @@ -273,7 +274,9 @@ module Gem ] end + ## # Load custom marshal format, re-initializing defaults as needed + def self._load(str) array = Marshal.load str @@ -282,9 +285,15 @@ module Gem current_version = CURRENT_SPECIFICATION_VERSION - field_count = MARSHAL_FIELDS[spec.specification_version] + field_count = if spec.specification_version > current_version then + spec.instance_variable_set :@specification_version, + current_version + MARSHAL_FIELDS[current_version] + else + MARSHAL_FIELDS[spec.specification_version] + end - if field_count.nil? or array.size < field_count then + if array.size < field_count then raise TypeError, "invalid Gem::Specification format #{array.inspect}" end diff --git a/lib/rubygems/test_utilities.rb b/lib/rubygems/test_utilities.rb index 0486db2b32..e8709b9be3 100644 --- a/lib/rubygems/test_utilities.rb +++ b/lib/rubygems/test_utilities.rb @@ -30,7 +30,7 @@ class Gem::FakeFetcher @paths = [] end - def fetch_path(path) + def fetch_path path, mtime = nil path = path.to_s @paths << path raise ArgumentError, 'need full URI' unless path =~ %r'^http://' @@ -40,7 +40,12 @@ class Gem::FakeFetcher raise Gem::RemoteFetcher::FetchError.new('no data', path) end - data.respond_to?(:call) ? data.call : data + if data.respond_to?(:call) then + data.call + else + data = Gem.gunzip data if path.to_s =~ /gz$/ unless data.empty? + data + end end def fetch_size(path) diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb index c5ae47b7eb..2ad961972b 100644 --- a/lib/rubygems/uninstaller.rb +++ b/lib/rubygems/uninstaller.rb @@ -30,7 +30,7 @@ class Gem::Uninstaller @force_executables = options[:executables] @force_all = options[:all] @force_ignore = options[:ignore] - @bin_dir = options[:bin_dir] + @bin_dir = options[:bin_dir] end ## @@ -41,17 +41,17 @@ class Gem::Uninstaller list = Gem.source_index.search(/^#{@gem}$/, @version) if list.empty? then - raise Gem::InstallError, "Unknown gem #{@gem}-#{@version}" + raise Gem::InstallError, "Unknown gem #{@gem} #{@version}" elsif list.size > 1 && @force_all - remove_all(list.dup) + remove_all(list.dup) remove_executables(list.last) - elsif list.size > 1 - say + elsif list.size > 1 + say gem_names = list.collect {|gem| gem.full_name} + ["All versions"] gem_name, index = choose_from_list("Select gem to uninstall:", gem_names) if index == list.size - remove_all(list.dup) + remove_all(list.dup) remove_executables(list.last) elsif index >= 0 && index < list.size to_remove = list[index] @@ -65,7 +65,7 @@ class Gem::Uninstaller remove_executables(list.last) end end - + ## # Removes installed executables and batch files (windows only) for # +gemspec+. @@ -111,7 +111,7 @@ class Gem::Uninstaller end end end - + ## # Removes all gems in +list+. # -- cgit v1.2.3