Class: Rupert::RPM::Lead

Inherits:
Object
  • Object
show all
Defined in:
lib/rupert/rpm/lead.rb

Constant Summary collapse

LEAD_LENGTH =

Lead has a fixed length

96.freeze
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`.

"\xed\xab\xee\xdb".force_encoding(Encoding::ASCII_8BIT).freeze
TYPE_BINARY =

RPM of type binary

0.freeze
TYPE_SOURCE =

RPM of type source

1.freeze
SIGNATURE_TYPE_HEADER =

Only valid and recognized signature type

5.freeze
@@arch_map =
{
  1 => "i386/x86_64"
}.freeze
@@os_map =
{
  1 => "Linux"
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lead) ⇒ Lead

Initializes a lead section, parsing given IO

Parameters:

  • lead (IO)

    An IO containing the lead information at the start


48
49
50
51
# File 'lib/rupert/rpm/lead.rb', line 48

def initialize(lead)
  lead_data = lead.read(LEAD_LENGTH)
  parse(lead_data) if lead_data
end

Class Method Details

.chomp(io) ⇒ Rupert::RPM::Lead, IO

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.

Parameters:

  • io (IO)

    IO object containing lead data at its start, possibly with additional bytes at the end

Returns:

  • (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.


41
42
43
# File 'lib/rupert/rpm/lead.rb', line 41

def self.chomp(io)
  [ self.new(io), io ]
end

Instance Method Details

#archString

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

Returns:

  • (String)

    a string representing the architecture name(s)


97
98
99
# File 'lib/rupert/rpm/lead.rb', line 97

def arch
  @@arch_map[@archnum]
end

#binary_type?Boolean

Returns ‘true` if lead reports RPM as of binary type.

Returns:

  • (Boolean)

    ‘true` if lead reports RPM as of binary type


83
84
85
# File 'lib/rupert/rpm/lead.rb', line 83

def binary_type?
  @type == TYPE_BINARY
end

#nameString

The name of the package

Returns:

  • (String)

    package name in the form <name>-<version>-<rev>.<suffix>


104
105
106
# File 'lib/rupert/rpm/lead.rb', line 104

def name
  @name
end

#osString

OS for which the package was built

Returns:

  • (String)

    OS canonical name as defined in ‘/usr/lib/rpm/rpmrc`


111
112
113
# File 'lib/rupert/rpm/lead.rb', line 111

def os
  @@os_map[@osnum]
end

#reservedString

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

Returns:

  • (String)

    the raw 16 bytes long reserved string at the end of the lead


125
126
127
# File 'lib/rupert/rpm/lead.rb', line 125

def reserved
  @reserved
end

#rpm?Boolean

Tells if the file is recognized as an RPM or not

Returns:

  • (Boolean)

    ‘true` if magic number is found at lead’s start, ‘false` otherwise


78
79
80
# File 'lib/rupert/rpm/lead.rb', line 78

def rpm?
  @magic == MAGIC
end

#rpm_versionString

RPM version used to format the package

Returns:

  • (String)

    RPM version in <major>.<minor> format


70
71
72
# File 'lib/rupert/rpm/lead.rb', line 70

def rpm_version
  "#{rpm_version_major}.#{rpm_version_minor}"
end

#rpm_version_majorFixnum

Major number of the RPM version used to format the package

Returns:

  • (Fixnum)

    RPM major version number


56
57
58
# File 'lib/rupert/rpm/lead.rb', line 56

def rpm_version_major
  @rpm_major
end

#rpm_version_minorFixnum

Minor number of the RPM version used to format the package

Returns:

  • (Fixnum)

    RPM minor version number


63
64
65
# File 'lib/rupert/rpm/lead.rb', line 63

def rpm_version_minor
  @rpm_minor
end

#signed?Boolean

Returns ‘true` if the RPM is recognized as being signed, `false` otherwise.

Returns:

  • (Boolean)

    ‘true` if the RPM is recognized as being signed, `false` otherwise


116
117
118
# File 'lib/rupert/rpm/lead.rb', line 116

def signed?
  @signature_type == SIGNATURE_TYPE_HEADER
end

#source_type?Boolean

Returns ‘true` if lead reports RPM as of source type.

Returns:

  • (Boolean)

    ‘true` if lead reports RPM as of source type


88
89
90
# File 'lib/rupert/rpm/lead.rb', line 88

def source_type?
  @type == TYPE_SOURCE
end