mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to RubyGems 1.3.4 r2223
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a6afbaeb3b
commit
31c94ffeb5
126 changed files with 7610 additions and 3747 deletions
|
@ -6,10 +6,17 @@
|
|||
|
||||
require 'find'
|
||||
|
||||
require 'rubygems/digest/md5'
|
||||
require 'digest'
|
||||
require 'rubygems/format'
|
||||
require 'rubygems/installer'
|
||||
|
||||
# Load test-unit 2.x if it's a gem
|
||||
begin
|
||||
Gem.activate('test-unit')
|
||||
rescue Gem::LoadError
|
||||
# Ignore - use the test-unit library that's part of the standard library
|
||||
end
|
||||
|
||||
##
|
||||
# Validator performs various gem file and gem database validation
|
||||
|
||||
|
@ -33,7 +40,7 @@ class Gem::Validator
|
|||
sum_data = gem_data.gsub(/MD5SUM = "([a-z0-9]+)"/,
|
||||
"MD5SUM = \"#{"F" * 32}\"")
|
||||
|
||||
unless Gem::MD5.hexdigest(sum_data) == $1.to_s then
|
||||
unless Digest::MD5.hexdigest(sum_data) == $1.to_s then
|
||||
raise Gem::VerificationError, 'invalid checksum for gem file'
|
||||
end
|
||||
end
|
||||
|
@ -48,7 +55,7 @@ class Gem::Validator
|
|||
gem_data = file.read
|
||||
verify_gem gem_data
|
||||
end
|
||||
rescue Errno::ENOENT
|
||||
rescue Errno::ENOENT, Errno::EINVAL
|
||||
raise Gem::VerificationError, "missing gem file #{gem_path}"
|
||||
end
|
||||
|
||||
|
@ -56,13 +63,11 @@ class Gem::Validator
|
|||
|
||||
def find_files_for_gem(gem_directory)
|
||||
installed_files = []
|
||||
Find.find(gem_directory) {|file_name|
|
||||
fn = file_name.slice((gem_directory.size)..(file_name.size-1)).sub(/^\//, "")
|
||||
if(!(fn =~ /CVS/ || File.directory?(fn) || fn == "")) then
|
||||
installed_files << fn
|
||||
end
|
||||
|
||||
}
|
||||
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
|
||||
|
||||
|
@ -81,55 +86,84 @@ class Gem::Validator
|
|||
#
|
||||
# returns a hash of ErrorData objects, keyed on the problem gem's name.
|
||||
|
||||
def alien
|
||||
errors = {}
|
||||
def alien(gems=[])
|
||||
errors = Hash.new { |h,k| h[k] = {} }
|
||||
|
||||
Gem::SourceIndex.from_installed_gems.each do |gem_name, gem_spec|
|
||||
errors[gem_name] ||= []
|
||||
next unless gems.include? gem_spec.name unless gems.empty?
|
||||
|
||||
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)
|
||||
install_dir = gem_spec.installation_path
|
||||
gem_path = File.join(install_dir, "cache", gem_spec.full_name) + ".gem"
|
||||
spec_path = File.join(install_dir, "specifications",
|
||||
gem_spec.full_name) + ".gemspec"
|
||||
gem_directory = gem_spec.full_gem_path
|
||||
|
||||
installed_files = find_files_for_gem(gem_directory)
|
||||
unless File.directory? gem_directory then
|
||||
errors[gem_name][gem_spec.full_name] =
|
||||
"Gem registered but doesn't exist at #{gem_directory}"
|
||||
next
|
||||
end
|
||||
|
||||
unless File.exist? spec_path then
|
||||
errors[gem_name] << ErrorData.new(spec_path, "Spec file doesn't exist for installed gem")
|
||||
errors[gem_name][spec_path] = "Spec file missing for installed gem"
|
||||
end
|
||||
|
||||
begin
|
||||
verify_gem_file(gem_path)
|
||||
|
||||
good, gone, unreadable = nil, nil, nil, nil
|
||||
|
||||
open gem_path, Gem.binary_mode 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'])
|
||||
|
||||
next unless data # HACK `gem check -a mkrf`
|
||||
good, gone = format.file_entries.partition { |entry, _|
|
||||
File.exist? File.join(gem_directory, entry['path'])
|
||||
}
|
||||
|
||||
open File.join(gem_directory, entry['path']), Gem.binary_mode 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")
|
||||
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'])
|
||||
}
|
||||
|
||||
unreadable.map! { |entry, _| entry['path'] }
|
||||
unreadable.sort.each do |path|
|
||||
errors[gem_name][path] = "Unreadable file"
|
||||
end
|
||||
|
||||
good.each do |entry, data|
|
||||
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
|
||||
errors[gem_name][entry['path']] = "Modified from original"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue Gem::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}")
|
||||
installed_files = find_files_for_gem(gem_directory)
|
||||
good.map! { |entry, _| entry['path'] }
|
||||
extras = installed_files - good - unreadable
|
||||
|
||||
extras.each do |extra|
|
||||
errors[gem_name][extra] = "Extra file"
|
||||
end
|
||||
rescue Gem::VerificationError => e
|
||||
errors[gem_name][gem_path] = e.message
|
||||
end
|
||||
end
|
||||
|
||||
errors.each do |name, subhash|
|
||||
errors[name] = subhash.map { |path, msg| ErrorData.new(path, msg) }
|
||||
end
|
||||
|
||||
errors
|
||||
end
|
||||
|
||||
|
@ -167,7 +201,7 @@ class Gem::Validator
|
|||
def unit_test(gem_spec)
|
||||
start_dir = Dir.pwd
|
||||
Dir.chdir(gem_spec.full_gem_path)
|
||||
$: << File.join(Gem.dir, "gems", gem_spec.full_name)
|
||||
$: << gem_spec.full_gem_path
|
||||
# XXX: why do we need this gem_spec when we've already got 'spec'?
|
||||
test_files = gem_spec.test_files
|
||||
|
||||
|
@ -200,7 +234,6 @@ class Gem::Validator
|
|||
Dir.chdir(start_dir)
|
||||
end
|
||||
|
||||
private
|
||||
def remove_leading_dot_dir(path)
|
||||
path.sub(/^\.\//, "")
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue