From 9694bb8cac12969300692dac5a1cf7aa4e3a46cd Mon Sep 17 00:00:00 2001 From: drbrain Date: Thu, 29 Nov 2012 06:52:18 +0000 Subject: * lib/rubygems*: Updated to RubyGems 2.0 * test/rubygems*: ditto. * common.mk (prelude): Updated for RubyGems 2.0 source rearrangement. * tool/change_maker.rb: Allow invalid UTF-8 characters in source files. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37976 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems/validator.rb | 73 +++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 40 deletions(-) (limited to 'lib/rubygems/validator.rb') diff --git a/lib/rubygems/validator.rb b/lib/rubygems/validator.rb index ffeed88660..f66b2c1f43 100644 --- a/lib/rubygems/validator.rb +++ b/lib/rubygems/validator.rb @@ -4,7 +4,7 @@ # See LICENSE.txt for permissions. #++ -require 'rubygems/format' +require 'rubygems/package' require 'rubygems/installer' ## @@ -16,7 +16,6 @@ class Gem::Validator def initialize require 'find' - require 'digest' end ## @@ -24,20 +23,8 @@ class Gem::Validator # gem_data:: [String] Contents of the gem file def verify_gem(gem_data) - raise Gem::VerificationError, 'empty gem file' if gem_data.size == 0 - - unless gem_data =~ /MD5SUM/ then - return # Don't worry about it...this sucks. Need to fix MD5 stuff for - # new format - # FIXME - end - - sum_data = gem_data.gsub(/MD5SUM = "([a-z0-9]+)"/, - "MD5SUM = \"#{"F" * 32}\"") - - unless Digest::MD5.hexdigest(sum_data) == $1.to_s then - raise Gem::VerificationError, 'invalid checksum for gem file' - end + # TODO remove me? The code here only validate an MD5SUM that was + # in some old formatted gems, but hasn't been for a long time. end ## @@ -58,17 +45,27 @@ class Gem::Validator def find_files_for_gem(gem_directory) installed_files = [] + Find.find gem_directory do |file_name| fn = file_name[gem_directory.size..file_name.size-1].sub(/^\//, "") installed_files << fn unless fn =~ /CVS/ || fn.empty? || File.directory?(file_name) end + installed_files end public - ErrorData = Struct.new :path, :problem + ErrorData = Struct.new :path, :problem do + + def <=> other + return nil unless self.class === other + + [path, problem] <=> [other.path, other.problem] + end + + end ## # Checks the gem directory for the following potential @@ -80,20 +77,22 @@ class Gem::Validator # * 1 cache - 1 spec - 1 directory. # # returns a hash of ErrorData objects, keyed on the problem gem's name. + #-- + # TODO needs further cleanup def alien(gems=[]) errors = Hash.new { |h,k| h[k] = {} } - Gem::SourceIndex.from_installed_gems.each do |gem_name, gem_spec| - next unless gems.include? gem_spec.name unless gems.empty? + Gem::Specification.each do |spec| + next unless gems.include? spec.name unless gems.empty? - install_dir = gem_spec.installation_path - gem_path = Gem.cache_gem(gem_spec.file_name, install_dir) - spec_path = File.join install_dir, "specifications", gem_spec.spec_name - gem_directory = gem_spec.full_gem_path + gem_name = spec.file_name + gem_path = spec.cache_file + spec_path = spec.spec_file + gem_directory = spec.full_gem_path unless File.directory? gem_directory then - errors[gem_name][gem_spec.full_name] = + errors[gem_name][spec.full_name] = "Gem registered but doesn't exist at #{gem_directory}" next end @@ -108,19 +107,18 @@ class Gem::Validator good, gone, unreadable = nil, nil, nil, nil open gem_path, Gem.binary_mode do |file| - format = Gem::Format.from_file_by_path(gem_path) + package = Gem::Package.new gem_path - good, gone = format.file_entries.partition { |entry, _| - File.exist? File.join(gem_directory, entry['path']) + good, gone = package.contents.partition { |file_name| + File.exist? File.join(gem_directory, file_name) } - gone.map! { |entry, _| entry['path'] } gone.sort.each do |path| errors[gem_name][path] = "Missing file" end - good, unreadable = good.partition { |entry, _| - File.readable? File.join(gem_directory, entry['path']) + good, unreadable = good.partition { |file_name| + File.readable? File.join(gem_directory, file_name) } unreadable.map! { |entry, _| entry['path'] } @@ -132,9 +130,10 @@ class Gem::Validator begin next unless data # HACK `gem check -a mkrf` - open File.join(gem_directory, entry['path']), Gem.binary_mode do |f| - unless Digest::MD5.hexdigest(f.read).to_s == - Digest::MD5.hexdigest(data).to_s then + source = File.join gem_directory, entry['path'] + + open source, Gem.binary_mode do |f| + unless f.read == data then errors[gem_name][entry['path']] = "Modified from original" end end @@ -143,7 +142,6 @@ class Gem::Validator end installed_files = find_files_for_gem(gem_directory) - good.map! { |entry, _| entry['path'] } extras = installed_files - good - unreadable extras.each do |extra| @@ -155,15 +153,10 @@ class Gem::Validator end errors.each do |name, subhash| - errors[name] = subhash.map { |path, msg| ErrorData.new(path, msg) } + errors[name] = subhash.map { |path, msg| ErrorData.new(path, msg) }.sort end errors end - - def remove_leading_dot_dir(path) - path.sub(/^\.\//, "") - end - end -- cgit v1.2.3