class RPM::DB

Public Class Methods

each() { |pkg| ... } click to toggle source

@deprecated Use RPM::Transaction#each

# File lib/rpm/db.rb, line 105
def self.each
  DB.open do |db|
    it = MatchIterator.from_ptr(RPM::C.rpmdbInitIterator(db.ptr, 0, nil, 0))
    if block_given?
      it.each do |pkg|
        yield pkg
      end
    end
  end
end
new(ts, opts={}) click to toggle source

@visibility private @param ts [Transaction] transaction object

# File lib/rpm/db.rb, line 11
def initialize(ts, opts={})
  opts[:writable] ||= false

  @ts = ts
  RPM::C.rpmtsOpenDB(@ts.ptr, opts[:writable] ? Fcntl::O_RDWR | Fcntl::O_CREAT : Fcntl::O_RDONLY )
end
open(writable=false, root='/', &block) click to toggle source

The package database is opened, but transactional processing (@see RPM::DB#transaction) cannot be done for when writable is false. When writable is false then the generated object gets freezed. @param [Boolean] writable Whether the database is writable. Default is false. @param [String] root Root path for the database, default is empty. @return [RPM::DB]

@example

db = RPM::DB.open
db.each do |pkg|
  puts pkg.name
end
# File lib/rpm/db.rb, line 76
def self.open(writable=false, root='/', &block)
  open_for_transaction(Transaction.new(:root => root), :writable => false, &block)
end
open_for_transaction(ts, opts={}) { |db| ... } click to toggle source

@visibility private

# File lib/rpm/db.rb, line 81
def self.open_for_transaction(ts, opts={})
  db = new(ts, opts)
  return db unless block_given?

  begin
    yield db
  ensure
    db.close unless db.closed?
  end
end

Public Instance Methods

close() click to toggle source
# File lib/rpm/db.rb, line 54
def close
  RPM::C.rpmtsCloseDB(@ts.ptr)
end
closed?() click to toggle source
# File lib/rpm/db.rb, line 58
def closed?
  ptr.null?
end
count_packages(name) click to toggle source

@return number of instances of name in the database

# File lib/rpm/db.rb, line 118
def count_packages(name)
end
each(&block) click to toggle source

@yield [Package] Called for each package in the database @example

db.each do |pkg|
  puts pkg.name
end
# File lib/rpm/db.rb, line 45
def each(&block)
  @ts.each(&block)
end
each_match(key, val, &block) click to toggle source

@yield [Package] Called for each match @param [Number] key RPM tag key @param [String] val Value to match @example

RPM.transaction do |t|
  t.each_match(RPM::TAG_ARCH, "x86_64") do |pkg|
    puts pkg.name
  end
end
# File lib/rpm/db.rb, line 34
def each_match(key, val, &block)
  @ts.each_match(key, val, &block)
end
home() click to toggle source

@deprecated Not possible to get home value in

newer RPM versions
# File lib/rpm/db.rb, line 95
def home
  raise NotImplementedError
end
init_iterator(tag, val) click to toggle source

@return [RPM::MatchIterator] Creates an iterator for tag and val

# File lib/rpm/db.rb, line 19
def init_iterator(tag, val)
  @ts.init_iterator(tag, val)
end
ptr() click to toggle source

@visibility private

# File lib/rpm/db.rb, line 50
def ptr
  RPM::C.rpmtsGetRdb(@ts.ptr)
end
root() click to toggle source

@return [String] The root path of the database

# File lib/rpm/db.rb, line 100
def root
  RPM::C.rpmtsRootDir(@ts.ptr)
end