summaryrefslogtreecommitdiff
path: root/lib/rubygems/format.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-22 02:52:35 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-02-22 02:52:35 +0000
commitb551e8c8b36766651be4e782e09e3b02e7d14a10 (patch)
treee164a1ef908bd4451568abf05b688f1593915b81 /lib/rubygems/format.rb
parent65544f575b25b18dc27f9364f973556ddb48538f (diff)
* lib/rubygems: update to 1.3.6.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26728 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/format.rb')
-rw-r--r--lib/rubygems/format.rb36
1 files changed, 16 insertions, 20 deletions
diff --git a/lib/rubygems/format.rb b/lib/rubygems/format.rb
index 80aae56215..82eaf9e77e 100644
--- a/lib/rubygems/format.rb
+++ b/lib/rubygems/format.rb
@@ -14,25 +14,22 @@ require 'rubygems/package'
class Gem::Format
- attr_accessor :spec, :file_entries, :gem_path
+ attr_accessor :spec
+ attr_accessor :file_entries
+ attr_accessor :gem_path
extend Gem::UserInteraction
##
- # Constructs an instance of a Format object, representing the gem's
- # data structure.
- #
- # gem:: [String] The file name of the gem
- #
+ # Constructs a Format representing the gem's data which came from +gem_path+
+
def initialize(gem_path)
@gem_path = gem_path
end
##
- # Reads the named gem file and returns a Format object, representing
- # the data from the gem file
- #
- # file_path:: [String] Path to the gem file
+ # Reads the gem +file_path+ using +security_policy+ and returns a Format
+ # representing the data in the gem
def self.from_file_by_path(file_path, security_policy = nil)
format = nil
@@ -41,25 +38,24 @@ class Gem::Format
raise Gem::Exception, "Cannot load gem at [#{file_path}] in #{Dir.pwd}"
end
- # check for old version gem
- if File.read(file_path, 20).include?("MD5SUM =")
+ start = File.read file_path, 20
+
+ if start.nil? or start.length < 20 then
+ nil
+ elsif start.include?("MD5SUM =") # old version gems
require 'rubygems/old_format'
- format = Gem::OldFormat.from_file_by_path(file_path)
+ Gem::OldFormat.from_file_by_path file_path
else
open file_path, Gem.binary_mode do |io|
- format = from_io io, file_path, security_policy
+ from_io io, file_path, security_policy
end
end
-
- return format
end
##
- # Reads a gem from an io stream and returns a Format object, representing
- # the data from the gem file
- #
- # io:: [IO] Stream from which to read the gem
+ # Reads a gem from +io+ at +gem_path+ using +security_policy+ and returns a
+ # Format representing the data from the gem
def self.from_io(io, gem_path="(io)", security_policy = nil)
format = new gem_path