# File lib/rubygems/validator.rb, line 75
    def alien
      require 'rubygems/installer'
      require 'find'
      require 'md5'
      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
          require 'rubygems/format.rb'
          verify_gem_file(gem_path)
          File.open(gem_path) do |file|
            format = Gem::Format.from_file_by_path(gem_path)
            format.file_entries.each do |entry, data|
              # Found this file.  Delete it from list
              installed_files.delete remove_leading_dot_dir(entry['path'])
              File.open(File.join(gem_directory, entry['path']), 'rb') do |f|
                unless MD5.md5(f.read).to_s == MD5.md5(data).to_s
                  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
        # Clean out directories that weren't explicitly included in the gemspec
        # FIXME: This still allows arbitrary incorrect directories.
        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