Class: Rupert::RPM
- Inherits:
-
Object
- Object
- Rupert::RPM
- Defined in:
- lib/rupert/rpm.rb,
lib/rupert/rpm/lead.rb,
lib/rupert/rpm/entry.rb,
lib/rupert/rpm/index.rb,
lib/rupert/rpm/header.rb,
lib/rupert/rpm/signature.rb
Defined Under Namespace
Classes: Entry, Header, Index, Lead, Signature
Class Method Summary collapse
-
.load(filename) ⇒ Rupert::RPM
Loads a RPM file and parses its structure.
-
.rpm?(filename) ⇒ Boolean
Tells whether given filename points to a valid RPM or not.
Instance Method Summary collapse
-
#binary? ⇒ Boolean
true
if the RPM is of type binary,false
otherwise. -
#filenames ⇒ Array
List of installed files (full paths).
-
#initialize(lead, signature, content, header) ⇒ RPM
constructor
Initialize the RPM object, given its components.
-
#intact? ⇒ Boolean
Verifies package integrity.
-
#md5 ⇒ String
MD5 checksum stored in the package (base64 encoded).
-
#name ⇒ String
Full package name.
-
#os ⇒ String
OS for which the package was built.
-
#rpm_arch ⇒ String
Which architecture the package was built for, e.g.
-
#rpm_version ⇒ String
RPM version used to encode the package.
-
#signed? ⇒ Boolean
true
if the package is signed,false
otherwise. -
#source? ⇒ Boolean
true
if the RPM is of type source,false
otherwise. -
#uncompressed_size ⇒ Fixnum
Package uncompressed size.
Constructor Details
#initialize(lead, signature, content, header) ⇒ RPM
Initialize the RPM object, given its components.
This method is not intended to be used to instantiate RPM objects directly. Instead, use load for a more straightforward alternative.
46 47 48 49 50 51 |
# File 'lib/rupert/rpm.rb', line 46 def initialize(lead, signature, content, header) @lead = lead @signature = signature @content = content @header = header end |
Class Method Details
.load(filename) ⇒ Rupert::RPM
Loads a RPM file and parses its structure
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rupert/rpm.rb', line 16 def load(filename) raise NotAnRPM, "File #{filename} isn't a valid RPM" unless rpm?(filename) raw_io = File.open(filename, 'r') rpm = Parser.new(raw_io).parse raw_io.close return rpm end |
Instance Method Details
#binary? ⇒ Boolean
Returns true
if the RPM is of type binary, false
otherwise.
61 62 63 |
# File 'lib/rupert/rpm.rb', line 61 def binary? @lead.binary_type? end |
#filenames ⇒ Array
List of installed files (full paths).
139 140 141 142 143 144 145 |
# File 'lib/rupert/rpm.rb', line 139 def filenames @header.dirindexes.map { |idx| @header.dirnames[idx] }.zip(@header.basenames).map { |dir, name| File.join(dir, name) } end |
#intact? ⇒ Boolean
Verifies package integrity. Compares MD5 checksum stored in the package with checksum calculated over header(s) and payload (archive).
payload) is corrupted
117 118 119 |
# File 'lib/rupert/rpm.rb', line 117 def intact? @signature.md5 == Digest::MD5.digest(@content) end |
#md5 ⇒ String
MD5 checksum stored in the package (base64 encoded). To be used to check package integrity.
NOTE: This is not the MD5 of the whole package; rather, the digest is calculated over the header and payload, leaving out the lead and the signature header. I.e., running md5sum <myrpm> won’t held the same result as Rupert::RPM.load(‘<myrpm>’).md5.
108 109 110 |
# File 'lib/rupert/rpm.rb', line 108 def md5 Base64.strict_encode64(@signature.md5) end |
#name ⇒ String
Full package name
81 82 83 |
# File 'lib/rupert/rpm.rb', line 81 def name @header.name end |
#os ⇒ String
OS for which the package was built
89 90 91 |
# File 'lib/rupert/rpm.rb', line 89 def os @lead.os end |
#rpm_arch ⇒ String
Which architecture the package was built for, e.g. i386/x86_64
or arm
74 75 76 |
# File 'lib/rupert/rpm.rb', line 74 def rpm_arch @lead.arch end |
#rpm_version ⇒ String
RPM version used to encode the package.
56 57 58 |
# File 'lib/rupert/rpm.rb', line 56 def rpm_version @lead.rpm_version end |
#signed? ⇒ Boolean
Returns true
if the package is signed, false
otherwise.
94 95 96 |
# File 'lib/rupert/rpm.rb', line 94 def signed? @lead.signed? end |
#source? ⇒ Boolean
Returns true
if the RPM is of type source, false
otherwise.
66 67 68 |
# File 'lib/rupert/rpm.rb', line 66 def source? @lead.source_type? end |
#uncompressed_size ⇒ Fixnum
Package uncompressed size.
This is the size (in bytes) of the uncompressed archive, or if you prefer, package’s installed size.
NOTE: if reading a package built with native rpmbuild
, this number (which is stored in the RPM itself) might not be precise, as this thread explains.
131 132 133 |
# File 'lib/rupert/rpm.rb', line 131 def uncompressed_size @header.uncompressed_size end |