class Rupert::RPM::Lead

Constants

LEAD_FORMAT

:nodoc The format string passed to unpack to parse the lead

LEAD_LENGTH

Lead has a fixed length

MAGIC

The magic header that identifies an RPM beyond a shadow of a doubt, as every good RPM starts with hex +ed ab ee db+.

SIGNATURE_TYPE_HEADER

Only valid and recognized signature type

TYPE_BINARY

RPM of type binary

TYPE_SOURCE

RPM of type source

Public Class Methods

chomp(io) click to toggle source

Chomps given IO, producing a {Lead} object and returning the remaining part for subsequent processing.

Lead data is expected to begin at IO start, so returned scrap is basically the input IO without its first {Rupert::RPM::Lead::LEAD_LENGTH} bytes.

@param io [IO] IO object containing lead data at its start, possibly

with additional bytes at the end

@return [Rupert::RPM::Lead, IO] the lead object corresponding to the

data at the beginning of the IO, and the part of the input remaining
after parsing.
# File lib/rupert/rpm/lead.rb, line 41
def self.chomp(io)
  [ self.new(io), io ]
end
new(lead) click to toggle source

Initializes a lead section, parsing given IO

@param lead [IO] An IO containing the lead information at the start

# File lib/rupert/rpm/lead.rb, line 48
def initialize(lead)
  lead_data = lead.read(LEAD_LENGTH)
  parse(lead_data) if lead_data
end

Public Instance Methods

arch() click to toggle source

The architecture the package was built for. A list of supported architectures can be found in /usr/lib/rpm/rpmrc on RedHat based systems.

@return [String] a string representing the architecture name(s)

# File lib/rupert/rpm/lead.rb, line 97
def arch
  @@arch_map[@archnum]
end
binary_type?() click to toggle source

@return true if lead reports RPM as of binary type

# File lib/rupert/rpm/lead.rb, line 83
def binary_type?
  @type == TYPE_BINARY
end
name() click to toggle source

The name of the package

@return [String] package name in the form <name>-<version>-<rev>.<suffix>

# File lib/rupert/rpm/lead.rb, line 104
def name
  @name
end
os() click to toggle source

OS for which the package was built

@return [String] OS canonical name as defined in /usr/lib/rpm/rpmrc

# File lib/rupert/rpm/lead.rb, line 111
def os
  @@os_map[@osnum]
end
reserved() click to toggle source

String of reserved bits. It’s here for completeness of the lead’s implementation but it isn’t intended to be actually used

@return [String] the raw 16 bytes long reserved string at the end of

the lead
# File lib/rupert/rpm/lead.rb, line 125
def reserved
  @reserved
end
rpm?() click to toggle source

Tells if the file is recognized as an RPM or not

@return true if magic number is found at lead’s start, false

otherwise
# File lib/rupert/rpm/lead.rb, line 78
def rpm?
  @magic == MAGIC
end
rpm_version() click to toggle source

RPM version used to format the package

@return [String] RPM version in <major>.<minor> format

# File lib/rupert/rpm/lead.rb, line 70
def rpm_version
  "#{rpm_version_major}.#{rpm_version_minor}"
end
rpm_version_major() click to toggle source

Major number of the RPM version used to format the package

@return [Fixnum] RPM major version number

# File lib/rupert/rpm/lead.rb, line 56
def rpm_version_major
  @rpm_major
end
rpm_version_minor() click to toggle source

Minor number of the RPM version used to format the package

@return [Fixnum] RPM minor version number

# File lib/rupert/rpm/lead.rb, line 63
def rpm_version_minor
  @rpm_minor
end
signed?() click to toggle source

@return true if the RPM is recognized as being signed, false otherwise

# File lib/rupert/rpm/lead.rb, line 116
def signed?
  @signature_type == SIGNATURE_TYPE_HEADER
end
source_type?() click to toggle source

@return true if lead reports RPM as of source type

# File lib/rupert/rpm/lead.rb, line 88
def source_type?
  @type == TYPE_SOURCE
end

Private Instance Methods

parse(lead_data) click to toggle source

:nodoc Unpacks lead raw bytes into its semantic components

# File lib/rupert/rpm/lead.rb, line 137
def parse(lead_data)
  @magic, @rpm_major, @rpm_minor, @type, @archnum, @name, @osnum,
      @signature_type, @reserved = lead_data.unpack(LEAD_FORMAT)
end