class Rupert::RPM

Public Class Methods

load(filename) click to toggle source

Loads a RPM file and parses its structure

@param filename [String] filename of the RPM to load @return [Rupert::RPM] the parsed RPM

# 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
new(lead, signature, content, header) click to toggle source

Initialize the RPM object, given its components.

This method is not intended to be used to instantiate RPM objects directly. Instead, use {Rupert::RPM.load} for a more straightforward alternative.

@param lead [Rupert::RPM::Lead] RPM lead section @param signature [Rupert::RPM::Signature] RPM signature information @param content [String] Raw content found after the signature structure @param header [Rupert::RPM::Header] RPM header holding package metadata

# File lib/rupert/rpm.rb, line 46
def initialize(lead, signature, content, header)
  @lead = lead
  @signature = signature
  @content = content
  @header = header
end
rpm?(filename) click to toggle source

Tells whether given filename points to a valid RPM or not.

@param filename [String] filename to inspect @return true if file starts with the correct magic header

# File lib/rupert/rpm.rb, line 31
def rpm?(filename)
  Lead.new(File.open(filename, 'r')).rpm?
end

Public Instance Methods

binary?() click to toggle source

@return true if the RPM is of type binary, false otherwise

# File lib/rupert/rpm.rb, line 61
def binary?
  @lead.binary_type?
end
filenames() click to toggle source

List of installed files (full paths).

@return [Array] array of String, with entries corresponding to

absolute filenames
# 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?() click to toggle source

Verifies package integrity. Compares MD5 checksum stored in the package with checksum calculated over header(s) and payload (archive).

@return true if package is intact, false if package (either stored MD5 or payload) is corrupted

# File lib/rupert/rpm.rb, line 117
def intact?
  @signature.md5 == Digest::MD5.digest(@content)
end
md5() click to toggle source

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+.

@return [String] Base64-encoded MD5 checksum of package’s header and

payload, stored in the RPM itself
# File lib/rupert/rpm.rb, line 108
def md5
  Base64.strict_encode64(@signature.md5)
end
name() click to toggle source

Full package name

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

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

OS for which the package was built

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

names section
# File lib/rupert/rpm.rb, line 89
def os
  @lead.os
end
rpm_arch() click to toggle source

Which architecture the package was built for, e.g. i386/x86_64 or arm

@return [String] package architecture name

# File lib/rupert/rpm.rb, line 74
def rpm_arch
 @lead.arch
end
rpm_version() click to toggle source

RPM version used to encode the package.

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

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

@return true if the package is signed, false otherwise

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

@return true if the RPM is of type source, false otherwise

# File lib/rupert/rpm.rb, line 66
def source?
  @lead.source_type?
end
uncompressed_size() click to toggle source

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.

@return [Fixnum] package uncompressed size (bytes)

# File lib/rupert/rpm.rb, line 131
def uncompressed_size
  @header.uncompressed_size
end