ruby-win32/lib/ruby/site_ruby/1.8/rubygems/validator.rb
##
# Checks the gem directory for the following potential 
# inconsistencies/problems:
# * Checksum gem itself
# * For each file in each gem, check consistency of installed versions
# * Check for files that aren't part of the gem but are in the gems directory
# * 1 cache - 1 spec - 1 directory.  
# 
# returns a hash of ErrorData objects, keyed on the problem gem's name.
Checks the gem directory for the following potential
inconsistencies/problems:
Checksum gem itself
For each file in each gem, check consistency of installed versions
Check for files that aren't part of the gem but are in the gems directory
1 cache - 1 spec - 1 directory.

returns a hash of ErrorData objects, keyed on the problem gem's name.
Checks the gem directory for the following potential inconsistencies / problems : Checksum gem itself For each file in each gem check consistency of installed versions Check for files that aren ' t part of the gem but are in the gems directory 1 cache - 1 spec - 1 directory . returns a hash of ErrorData objects keyed on the problem gem ' s name .
def alien
      errors = {}
      Gem::SourceIndex.from_installed_gems.each do |gem_name, gem_spec|
        errors[gem_name] ||= []
        gem_path = File.join(Gem.dir, "cache", gem_spec.full_name) + ".gem"
        spec_path = File.join(Gem.dir, "specifications", gem_spec.full_name) + ".gemspec"
        gem_directory = File.join(Gem.dir, "gems", gem_spec.full_name)
        installed_files = find_files_for_gem(gem_directory)
        if(!File.exist?(spec_path)) then
          errors[gem_name] << ErrorData.new(spec_path, "Spec file doesn't exist for installed gem")
        end
        begin
          verify_gem_file(gem_path)
          File.open(gem_path, 'rb') do |file|
            format = Gem::Format.from_file_by_path(gem_path)
            format.file_entries.each do |entry, data|
              installed_files.delete remove_leading_dot_dir(entry['path'])
              next unless data 
              File.open(File.join(gem_directory, entry['path']), 'rb') do |f|
                unless Gem::MD5.hexdigest(f.read).to_s ==
                       Gem::MD5.hexdigest(data).to_s then
                  errors[gem_name] << ErrorData.new(entry['path'], "installed file doesn't match original from gem")
                end
              end
            end
          end
        rescue VerificationError => e
          errors[gem_name] << ErrorData.new(gem_path, e.message)
        end
        installed_files.delete_if {|potential_directory|        
          File.directory?(File.join(gem_directory, potential_directory))
        }
        if(installed_files.size > 0) then
          errors[gem_name] << ErrorData.new(gem_path, "Unmanaged files in gem: #{installed_files.inspect}")
        end
      end
      errors
    end
def alien errors = { } Gem :: SourceIndex . from_installed_gems . each do | gem_name , gem_spec | errors [ gem_name ] ||= [ ] gem_path = File . join ( Gem . dir , "cache" , gem_spec . full_name ) + ".gem" spec_path = File . join ( Gem . dir , "specifications" , gem_spec . full_name ) + ".gemspec" gem_directory = File . join ( Gem . dir , "gems" , gem_spec . full_name ) installed_files = find_files_for_gem ( gem_directory ) if ( ! File . exist? ( spec_path ) ) then errors [ gem_name ] << ErrorData . new ( spec_path , "Spec file doesn't exist for installed gem" ) end begin verify_gem_file ( gem_path ) File . open ( gem_path , 'rb' ) do | file | format = Gem :: Format . from_file_by_path ( gem_path ) format . file_entries . each do | entry , data | installed_files . delete remove_leading_dot_dir ( entry [ 'path' ] ) next unless data File . open ( File . join ( gem_directory , entry [ 'path' ] ) , 'rb' ) do | f | unless Gem :: MD5 . hexdigest ( f . read ) . to_s == Gem :: MD5 . hexdigest ( data ) . to_s then errors [ gem_name ] << ErrorData . new ( entry [ 'path' ] , "installed file doesn't match original from gem" ) end end end end rescue VerificationError => e errors [ gem_name ] << ErrorData . new ( gem_path , e . message ) end installed_files . delete_if { | potential_directory | File . directory? ( File . join ( gem_directory , potential_directory ) ) } if ( installed_files . size > 0 ) then errors [ gem_name ] << ErrorData . new ( gem_path , "Unmanaged files in gem: #{installed_files.inspect}" ) end end errors end
Checks the gem directory for the following potential
inconsistencies/problems:
 Checksum gem itself
 For each file in each gem, check consistency of installed versions
 Check for files that aren't part of the gem but are in the gems directory
 1 cache - 1 spec - 1 directory.
Checks the gem directory for the following potential inconsistencies / problems : Checksum gem itself For each file in each gem check consistency of installed versions Check for files that aren ' t part of the gem but are in the gems directory 1 cache - 1 spec - 1 directory .
# Found this file.  Delete it from list # HACK `gem check -a mkrf` # Clean out directories that weren't explicitly included in the gemspec # FIXME: This still allows arbitrary incorrect directories.