libzypp  17.35.14
zypp::target::rpm::librpmDb Class Reference

Manage access to librpm database. More...

#include <zypp/target/rpm/librpmDb.h>

Inheritance diagram for zypp::target::rpm::librpmDb:

Classes

class  D
 librpmDb internal database handle More...
 

Public Types

using Ptr = intrusive_ptr< librpmDb >
 
using constPtr = intrusive_ptr< const librpmDb >
 

Public Member Functions

 ~librpmDb () override
 Destructor. More...
 
const Pathnameroot () const
 
const PathnamedbPath () const
 
std::ostream & dumpOn (std::ostream &str) const override
 Dump debug info. More...
 
 db_const_iterator () ZYPP_DEPRECATED
 Open the default rpmdb below the host system (at /). More...
 
 db_const_iterator (const Pathname &root_r)
 Open the default rpmdb below the system at root_r. More...
 
 db_const_iterator (const Pathname &root_r, const Pathname &dbPath_r)
 Open a specific rpmdb below the system at root_r. More...
 
 db_const_iterator (std::nullptr_t)
 A null iterator. More...
 
 ~db_const_iterator ()
 Destructor. More...
 
bool hasDB () const
 Whether an underlying rpmdb exists. More...
 
void operator++ ()
 Advance to next RpmHeader::constPtr. More...
 
unsigned dbHdrNum () const
 Returns the current headers index in database, 0 if no header. More...
 
const RpmHeader::constPtroperator* () const
 Returns the current RpmHeader::constPtr or NULL, if no more entries available. More...
 
const RpmHeader::constPtroperator-> () const
 Forwards to the current RpmHeader::constPtr. More...
 
bool findAll ()
 Reset to iterate all packages. More...
 
bool findByFile (const std::string &file_r)
 Reset to iterate all packages that own a certain file. More...
 
bool findByProvides (const std::string &tag_r)
 Reset to iterate all packages that provide a certain tag. More...
 
bool findByRequiredBy (const std::string &tag_r)
 Reset to iterate all packages that require a certain tag. More...
 
bool findByConflicts (const std::string &tag_r)
 Reset to iterate all packages that conflict with a certain tag. More...
 
bool findByName (const std::string &name_r)
 Reset to iterate all packages with a certain name. More...
 
bool findPackage (const std::string &name_r)
 Find package by name. More...
 
bool findPackage (const std::string &name_r, const Edition &ed_r)
 Find package by name and edition. More...
 
bool findPackage (const Package::constPtr &which_r)
 Abbr. More...
 
- Public Member Functions inherited from zypp::base::ReferenceCounted
 ReferenceCounted ()
 Default ctor. More...
 
 ReferenceCounted (const ReferenceCounted &rhs)
 Copy ctor. More...
 
virtual ~ReferenceCounted ()
 Dtor. More...
 
ReferenceCountedoperator= (const ReferenceCounted &)
 Assignment. More...
 
unsigned refCount () const
 Return reference counter value. More...
 
void ref () const
 Add a reference. More...
 
void unref () const
 Release a reference. More...
 

Static Public Member Functions

static bool globalInit ()
 Initialize lib librpm (read configfiles etc.). More...
 
static std::string expand (const std::string &macro_r)
 
static Pathname suggestedDbPath (const Pathname &root_r)
 
static bool dbExists (const Pathname &root_r, const Pathname &dbPath_r=Pathname())
 
static librpmDb::constPtr dbOpenIf (const Pathname &root_r, const Pathname &dbPath_r=Pathname())
 Open the rpmdb below the system at root_r (if it exists). More...
 
static librpmDb::constPtr dbOpenCreate (const Pathname &root_r, const Pathname &dbPath_r=Pathname())
 Assert the rpmdb below the system at root_r exists. More...
 
- Static Public Member Functions inherited from zypp::base::ReferenceCounted
static void add_ref (const ReferenceCounted *ptr_r)
 Called by zypp::intrusive_ptr to add a reference. More...
 
static void release (const ReferenceCounted *ptr_r)
 Called by zypp::intrusive_ptr to add a reference. More...
 

Private Member Functions

 librpmDb (const Pathname &root_r, const Pathname &dbPath_r, bool readonly_r=true)
 Private constructor! librpmDb objects are to be created via static interface only. More...
 
void unref_to (unsigned refCount_r) const override
 Trigger from Rep, after refCount was decreased. More...
 
db_const_iteratoroperator= (const db_const_iterator &)
 
 db_const_iterator (const db_const_iterator &)
 

Static Private Member Functions

static void dbAccess (librpmDb::Ptr &ptr_r)
 INTENTIONALLY UNDEFINED<> because of bug in Ptr classes which allows implicit conversion from librpmDb::Ptr to librpmDb::constPtr. More...
 
static librpmDb::constPtr dbAccess (const Pathname &root_r, const Pathname &dbPath_r, bool create_r=false)
 Internal workhorse managing database creation and access. More...
 

Private Attributes

D_d
 

Friends

class librpmDb
 
std::ostream & operator<< (std::ostream &str, const db_const_iterator &obj)
 

Additional Inherited Members

- Protected Member Functions inherited from zypp::base::ReferenceCounted
virtual void ref_to (unsigned) const
 Trigger derived classes after refCount was increased. More...
 

Detailed Description

Manage access to librpm database.

Definition at line 51 of file librpmDb.h.

Member Typedef Documentation

◆ Ptr

◆ constPtr

Definition at line 55 of file librpmDb.h.

Constructor & Destructor Documentation

◆ librpmDb()

zypp::target::rpm::librpmDb::librpmDb ( const Pathname root_r,
const Pathname dbPath_r,
bool  readonly_r = true 
)
private

Private constructor! librpmDb objects are to be created via static interface only.

Definition at line 226 of file librpmDb.cc.

◆ ~librpmDb()

zypp::target::rpm::librpmDb::~librpmDb ( )
override

Destructor.

Closes rpmdb.

Definition at line 230 of file librpmDb.cc.

◆ ~db_const_iterator()

zypp::target::rpm::librpmDb::~db_const_iterator ( )

Destructor.

Member Function Documentation

◆ dbAccess() [1/2]

static void zypp::target::rpm::librpmDb::dbAccess ( librpmDb::Ptr ptr_r)
staticprivate

INTENTIONALLY UNDEFINED<> because of bug in Ptr classes which allows implicit conversion from librpmDb::Ptr to librpmDb::constPtr.

Currently we don't want to provide non const handles, as the database is opened READONLY.

Exceptions
RpmException

◆ globalInit()

bool zypp::target::rpm::librpmDb::globalInit ( )
static

Initialize lib librpm (read configfiles etc.).

It's called on demand but you may call it anytime.

Returns
Whether librpm is initialized.

Definition at line 138 of file librpmDb.cc.

◆ expand()

std::string zypp::target::rpm::librpmDb::expand ( const std::string &  macro_r)
static
Returns
librpm macro expansion.

Definition at line 158 of file librpmDb.cc.

◆ suggestedDbPath()

Pathname zypp::target::rpm::librpmDb::suggestedDbPath ( const Pathname root_r)
static
Returns
The preferred location of the rpmdb below root_r. It's the location of an already existing db, otherwise the default location suggested by rpm's config.
Exceptions
RpmExceptionif root is not an absolute path or no directory for the rpmdb can determined.

Definition at line 170 of file librpmDb.cc.

◆ dbExists()

bool zypp::target::rpm::librpmDb::dbExists ( const Pathname root_r,
const Pathname dbPath_r = Pathname() 
)
static
Returns
whether the rpmdb below the system at root_r exists. Unless a dbPath_r is explicitly specified, the systems default rpmdb is used (
See also
suggestedDbPath).
Exceptions
RpmExceptionif no directory for the rpmdb can be determined.

Definition at line 182 of file librpmDb.cc.

◆ dbOpenIf()

librpmDb::constPtr zypp::target::rpm::librpmDb::dbOpenIf ( const Pathname root_r,
const Pathname dbPath_r = Pathname() 
)
static

Open the rpmdb below the system at root_r (if it exists).

If the database does not exist a nullptr is returned. Unless a dbPath_r is explicitly specified, the systems default rpmdb is used (

See also
suggestedDbPath).
Exceptions
RpmExceptionif an existing database can not be opened.

Definition at line 194 of file librpmDb.cc.

◆ dbOpenCreate()

librpmDb::constPtr zypp::target::rpm::librpmDb::dbOpenCreate ( const Pathname root_r,
const Pathname dbPath_r = Pathname() 
)
static

Assert the rpmdb below the system at root_r exists.

If the database does not exist an empty one is created. Unless a dbPath_r is explicitly specified, the systems default rpmdb is used (

See also
suggestedDbPath).
Exceptions
RpmExceptionif the database can not be created or opened.

Definition at line 197 of file librpmDb.cc.

◆ dbAccess() [2/2]

librpmDb::constPtr zypp::target::rpm::librpmDb::dbAccess ( const Pathname root_r,
const Pathname dbPath_r,
bool  create_r = false 
)
staticprivate

Internal workhorse managing database creation and access.

Exceptions
RpmExceptionif an existing database can not be opened.

Definition at line 200 of file librpmDb.cc.

◆ unref_to()

void zypp::target::rpm::librpmDb::unref_to ( unsigned  refCount_r) const
overrideprivatevirtual

Trigger from Rep, after refCount was decreased.

Reimplemented from zypp::base::ReferenceCounted.

Definition at line 236 of file librpmDb.cc.

◆ root()

const Pathname & zypp::target::rpm::librpmDb::root ( ) const
Returns
This handles root directory for all operations.

Definition at line 239 of file librpmDb.cc.

◆ dbPath()

const Pathname & zypp::target::rpm::librpmDb::dbPath ( ) const
Returns
This handles directory that contains the rpmdb.

Definition at line 242 of file librpmDb.cc.

◆ dumpOn()

std::ostream & zypp::target::rpm::librpmDb::dumpOn ( std::ostream &  str) const
overridevirtual

Dump debug info.

Reimplemented from zypp::base::ReferenceCounted.

Definition at line 245 of file librpmDb.cc.

◆ operator=()

db_const_iterator& zypp::target::rpm::librpmDb::operator= ( const db_const_iterator )
private

◆ db_const_iterator() [1/5]

zypp::target::rpm::librpmDb::db_const_iterator ( const db_const_iterator )
private

◆ db_const_iterator() [2/5]

zypp::target::rpm::librpmDb::db_const_iterator ( )

Open the default rpmdb below the host system (at /).

Deprecated:
It's preferred to explicitly tell the root directory of the system whose database you want to query.

◆ db_const_iterator() [3/5]

zypp::target::rpm::librpmDb::db_const_iterator ( const Pathname root_r)
explicit

Open the default rpmdb below the system at root_r.

◆ db_const_iterator() [4/5]

zypp::target::rpm::librpmDb::db_const_iterator ( const Pathname root_r,
const Pathname dbPath_r 
)

Open a specific rpmdb below the system at root_r.

◆ db_const_iterator() [5/5]

zypp::target::rpm::librpmDb::db_const_iterator ( std::nullptr_t  )

A null iterator.

What you get if the database does not exist.

◆ hasDB()

bool zypp::target::rpm::librpmDb::hasDB ( ) const

Whether an underlying rpmdb exists.

◆ operator++()

void zypp::target::rpm::librpmDb::operator++ ( )

Advance to next RpmHeader::constPtr.

◆ dbHdrNum()

unsigned zypp::target::rpm::librpmDb::dbHdrNum ( ) const

Returns the current headers index in database, 0 if no header.

◆ operator*()

const RpmHeader::constPtr& zypp::target::rpm::librpmDb::operator* ( ) const

Returns the current RpmHeader::constPtr or NULL, if no more entries available.

◆ operator->()

const RpmHeader::constPtr& zypp::target::rpm::librpmDb::operator-> ( ) const
inline

Forwards to the current RpmHeader::constPtr.

Definition at line 270 of file librpmDb.h.

◆ findAll()

bool zypp::target::rpm::librpmDb::findAll ( )

Reset to iterate all packages.

Returns true if iterator contains at least one entry.

◆ findByFile()

bool zypp::target::rpm::librpmDb::findByFile ( const std::string &  file_r)

Reset to iterate all packages that own a certain file.

◆ findByProvides()

bool zypp::target::rpm::librpmDb::findByProvides ( const std::string &  tag_r)

Reset to iterate all packages that provide a certain tag.

◆ findByRequiredBy()

bool zypp::target::rpm::librpmDb::findByRequiredBy ( const std::string &  tag_r)

Reset to iterate all packages that require a certain tag.

◆ findByConflicts()

bool zypp::target::rpm::librpmDb::findByConflicts ( const std::string &  tag_r)

Reset to iterate all packages that conflict with a certain tag.

◆ findByName()

bool zypp::target::rpm::librpmDb::findByName ( const std::string &  name_r)

Reset to iterate all packages with a certain name.

NOTE: Multiple entries for one package installed in different versions are possible but not desired. Usually you'll want to use findPackage instead.

findByName is needed to retrieve pseudo packages like 'gpg-pubkey', which in fact exist in multiple instances.

◆ findPackage() [1/3]

bool zypp::target::rpm::librpmDb::findPackage ( const std::string &  name_r)

Find package by name.

Multiple entries for one package installed in different versions are possible but not desired. If so, the last package installed is returned.

◆ findPackage() [2/3]

bool zypp::target::rpm::librpmDb::findPackage ( const std::string &  name_r,
const Edition ed_r 
)

Find package by name and edition.

Commonly used by PMRpmPackageDataProvider.

◆ findPackage() [3/3]

bool zypp::target::rpm::librpmDb::findPackage ( const Package::constPtr which_r)

Abbr.

for findPackage( which_r->name(), which_r->edition() );

Friends And Related Function Documentation

◆ librpmDb

friend class librpmDb
friend

Definition at line 202 of file librpmDb.h.

◆ operator<<

std::ostream& operator<< ( std::ostream &  str,
const db_const_iterator obj 
)
friend

Member Data Documentation

◆ _d

D & zypp::target::rpm::librpmDb::_d
private

Definition at line 146 of file librpmDb.h.


The documentation for this class was generated from the following files: