Skip to content

Commit

Permalink
- some code cleanup
Browse files Browse the repository at this point in the history
- start working on 'RPM' public api
  • Loading branch information
jordansissel committed Feb 19, 2012
1 parent 25459a4 commit c6695bb
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 18 deletions.
41 changes: 41 additions & 0 deletions lib/rpm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

require "rpm/namespace"

class RPM
def initialize
#@requires = []
#@conflicts = []
#@provides = []
#@files = []
#@scripts = {}
end

def self.read(path_or_io)
rpmfile = RPM::File.new(path_or_io)
header = rpmfile.header

header.tags.each do |tag|
p tag
end

# Things we care about in the header:
# * name, version, release, epoch, summary, description
# *
# * requires, provides, conflicts
# * scripts
# * payload format

#payload = rpmfile.payload
# Parse the payload, check the rpmfile.header to find tags describing the
# format of the payload.
# Initial target should be gzipped cpio.
end # def self.read

def files
return @files
end

# Write this RPM to an IO-like object (must respond to 'write')
def write(io)
end
end # class RPM
27 changes: 10 additions & 17 deletions lib/rpm/file/header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class RPM::File::Header

HEADER_SIGNED_TYPE = 5
HEADER_MAGIC = "\x8e\xad\xe8\x01\x00\x00\x00\x00"
# magic + index_count + data_length
HEADER_HEADER_LENGTH = HEADER_MAGIC.length + 4 + 4
TAG_ENTRY_SIZE = 16 # tag id, type, offset, count == 16 bytes

def initialize(file)
@file = file
Expand All @@ -34,40 +37,30 @@ def read
# header 'entries' are an
# int32 (tag id), int32 (tag type), int32 (offset), uint32 (count)
#
# len = sizeof(il) + sizeof(dl) + (il * sizeof(struct entryInfo_s)) + dl;
# See rpm's header.c, the headerLoad method function for reference.

# Header always starts with HEADER_MAGIC + index_count(2bytes) +
# data_length(2bytes)
data = @file.read(16).unpack("a8NN")
data = @file.read(HEADER_HEADER_LENGTH).unpack("a8NN")
# TODO(sissel): @index_count is really a count, rename?
@magic, @index_count, @data_length = data
validate

# TODO(sissel): Validate @magic

entry_size = 16 # tag id, type, offset, count == 16 bytes
@index_size = @index_count * entry_size
@index_size = @index_count * TAG_ENTRY_SIZE
tag_data = @file.read(@index_size)
data = @file.read(@data_length)

#ap :data => data

(0 ... @index_count).each do |i|
offset = i * entry_size
entry_data = tag_data[i * entry_size, entry_size]
offset = i * TAG_ENTRY_SIZE
entry_data = tag_data[i * TAG_ENTRY_SIZE, TAG_ENTRY_SIZE]
entry = entry_data.unpack("NNNN")
entry << data
tag = ::RPM::File::Tag.new(*entry)
@tags << tag

#ap tag.tag => {
#:type => tag.type,
#:offset => tag.offset,
#:count => tag.count,
#:value => (tag.value rescue "???"),
#}
end # each index
@length = @magic.size + @index_size + @data_length

@length = HEADER_HEADER_LENGTH + @index_size + @data_length
end # def read

def write
Expand Down
2 changes: 1 addition & 1 deletion lib/rpm/file/lead.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RPM::File::Lead

def initialize(file)
@file = file
@inspectables = [:@length, :@file]
@inspectables = [:@major, :@minor, :@length, :@type, :@archnum, :@signature_type, :@reserved, :@osnum]
end

def type
Expand Down

0 comments on commit c6695bb

Please sign in to comment.