libzypp  17.35.8
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
 
shared_ptr< RpmExceptionerror () const
 Return any database error. More...
 
bool valid () const
 
bool empty () const
 
unsigned size () const
 
void * dont_call_it () const
 Dont call it ;) It's for development and testing only. More...
 
std::ostream & dumpOn (std::ostream &str) const override
 Dump debug info. More...
 
 db_const_iterator (librpmDb::constPtr dbptr_r=0)
 Constructor. More...
 
 ~db_const_iterator ()
 Destructor. More...
 
shared_ptr< RpmExceptiondbError () const
 Return any database error. 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 std::string stringPath (const Pathname &root_r, const Pathname &sub_r)
 
static const PathnamedefaultRoot ()
 
static const PathnamedefaultDbPath ()
 
static Pathname suggestedDbPath (const Pathname &root_r)
 
static void dbAccess (const Pathname &root_r)
 Adjust access to the given database location, making it the new default location on success. More...
 
static void dbAccess (librpmDb::constPtr &ptr_r)
 Same as &ref dbAccess(), but returns the database handle if avaialble, otherwise NULL. More...
 
static unsigned dbRelease (bool force_r=false) ZYPP_API
 If there are no outstanding references to the database (e.g. More...
 
static unsigned blockAccess () ZYPP_API
 Blocks further access to rpmdb. More...
 
static unsigned blockAccess (const Pathname &root_r, const Pathname &dbPath_r)
 
static void unblockAccess () ZYPP_API
 Allow access to rpmdb e.g. More...
 
static bool isBlocked () ZYPP_API
 
static std::ostream & dumpState (std::ostream &str)
 Dump debug info. 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...
 

Protected Member Functions

 librpmDb (const Pathname &root_r, const Pathname &dbPath_r, bool readonly_r)
 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...
 
- Protected Member Functions inherited from zypp::base::ReferenceCounted
virtual void ref_to (unsigned) const
 Trigger derived classes after refCount was increased. More...
 

Private Member Functions

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 librpmDbnewLibrpmDb ()
 For internal use. More...
 
static void dbAccess ()
 Access the database at the current default location. More...
 

Private Attributes

D_d
 

Static Private Attributes

static Pathname _defaultRoot { "/" }
 Current root directory for all operations. More...
 
static Pathname _defaultDbPath
 Current directory (below root) that contains the rpmdb. More...
 
static Pathname _rpmDefaultDbPath
 _dbpath configured in rpm config. More...
 
static librpmDb::constPtr _defaultDb
 Current rpmdb handle. More...
 
static bool _dbBlocked ZYPP_API
 Whether access is blocked (no _defaultDb will be available). More...
 

Friends

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

Additional Inherited Members

Detailed Description

Manage access to librpm database.

Subclass to retrieve database content.

Definition at line 37 of file librpmDb.h.

Member Typedef Documentation

◆ Ptr

◆ constPtr

Definition at line 41 of file librpmDb.h.

Constructor & Destructor Documentation

◆ librpmDb()

zypp::target::rpm::librpmDb::librpmDb ( const Pathname root_r,
const Pathname dbPath_r,
bool  readonly_r 
)
protected

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

Definition at line 362 of file librpmDb.cc.

◆ ~librpmDb()

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

Destructor.

Closes rpmdb.

Definition at line 374 of file librpmDb.cc.

◆ ~db_const_iterator()

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

Destructor.

Member Function Documentation

◆ dbAccess() [1/4]

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

◆ newLibrpmDb()

librpmDb * zypp::target::rpm::librpmDb::newLibrpmDb ( )
staticprivate

For internal use.

Pointer returned should immediately be wrapped into librpmDb::Ptr.

Exceptions
RpmException

Definition at line 162 of file librpmDb.cc.

◆ dbAccess() [2/4]

void zypp::target::rpm::librpmDb::dbAccess ( )
staticprivate

Access the database at the current default location.

If necessary (eg. after dbRelease), the database is opened. This just creates the internal handle. Once the handle is passed to e.g. some db_const_iterator, the database will be closed if the last outstanding reference goes out of scope. If no external reference is created, you'll have to explicitly call dbRelease to close the database.

Exceptions
RpmException

Definition at line 244 of file librpmDb.cc.

◆ 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 111 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 142 of file librpmDb.cc.

◆ stringPath()

static std::string zypp::target::rpm::librpmDb::stringPath ( const Pathname root_r,
const Pathname sub_r 
)
inlinestatic
Returns
String '(root_r)sub_r' used in debug output.

Definition at line 130 of file librpmDb.h.

◆ defaultRoot()

static const Pathname& zypp::target::rpm::librpmDb::defaultRoot ( )
inlinestatic
Returns
Current root directory for all operations.

Definition at line 140 of file librpmDb.h.

◆ defaultDbPath()

static const Pathname& zypp::target::rpm::librpmDb::defaultDbPath ( )
inlinestatic
Returns
Current directory (below root) that contains the rpmdb.

Definition at line 148 of file librpmDb.h.

◆ 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 exising db, otherwise the default location sugested by rpms config.
Exceptions
RpmInvalidRootExceptionif root is not an absolute path or no directory for the rpmdb can determined.

no symlink

Definition at line 190 of file librpmDb.cc.

◆ dbAccess() [3/4]

void zypp::target::rpm::librpmDb::dbAccess ( const Pathname root_r)
static

Adjust access to the given database location, making it the new default location on success.

No relative Pathnames are allowed.

It's not possible to access a database while access is blocked (see blockAccess), but valid Pathnames provided will be stored as new default location.

It's not allowed to switch to another location while a database is accessed. Use dbRelease to force releasing the database first.

Exceptions
RpmException

Definition at line 219 of file librpmDb.cc.

◆ dbAccess() [4/4]

void zypp::target::rpm::librpmDb::dbAccess ( librpmDb::constPtr ptr_r)
static

Same as &ref dbAccess(), but returns the database handle if avaialble, otherwise NULL.

This creates an external reference, thus it should not be used longer than necessary. Be prepared that the handle might become invalid (see dbRelease) later.

Exceptions
RpmException

Definition at line 264 of file librpmDb.cc.

◆ dbRelease()

unsigned zypp::target::rpm::librpmDb::dbRelease ( bool  force_r = false)
static

If there are no outstanding references to the database (e.g.

by db_const_iterator), the database is closed. Subsequent calls to dbAccess may however open the database again.

If forced, the internal reference is dropped and it will look like the database was closed. But physically the database will be closed after all outstanding references are gone.

Returns
The number of outstandig references to the database, 0 if if database was physically closed.

Definition at line 277 of file librpmDb.cc.

◆ blockAccess() [1/2]

unsigned zypp::target::rpm::librpmDb::blockAccess ( )
static

Blocks further access to rpmdb.

Basically the same as dbRelease( true ), but subsequent calls to dbAccess will fail returning E_RpmDB_access_blocked.

Returns
The number of outstandig references to the database, 0 if if database was physically closed.

Definition at line 314 of file librpmDb.cc.

◆ blockAccess() [2/2]

static unsigned zypp::target::rpm::librpmDb::blockAccess ( const Pathname root_r,
const Pathname dbPath_r 
)
inlinestatic

Definition at line 216 of file librpmDb.h.

◆ unblockAccess()

void zypp::target::rpm::librpmDb::unblockAccess ( )
static

Allow access to rpmdb e.g.

after blockAccess. Subsequent calls to dbAccess will perform.

NOTE: Initially we're in blocked mode. So you must call unblockAccess unblockAccess at least once. Othwise nothing will happen.

Returns
The number of outstandig references to the database, 0 if if database was physically closed.

Definition at line 327 of file librpmDb.cc.

◆ isBlocked()

static bool zypp::target::rpm::librpmDb::isBlocked ( )
inlinestatic
Returns
Whether database access is blocked.

Definition at line 236 of file librpmDb.h.

◆ dumpState()

std::ostream & zypp::target::rpm::librpmDb::dumpState ( std::ostream &  str)
static

Dump debug info.

Definition at line 339 of file librpmDb.cc.

◆ unref_to()

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

Trigger from Rep, after refCount was decreased.

Reimplemented from zypp::base::ReferenceCounted.

Definition at line 385 of file librpmDb.cc.

◆ root()

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

Definition at line 399 of file librpmDb.cc.

◆ dbPath()

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

Definition at line 410 of file librpmDb.cc.

◆ error()

shared_ptr< RpmException > zypp::target::rpm::librpmDb::error ( ) const

Return any database error.

Usg. if the database was blocked by calling dbRelease(true) or blockAccess.

Definition at line 421 of file librpmDb.cc.

◆ valid()

bool zypp::target::rpm::librpmDb::valid ( ) const
inline
Returns
Whether handle is valid.

Definition at line 305 of file librpmDb.h.

◆ empty()

bool zypp::target::rpm::librpmDb::empty ( ) const
Returns
True if handle is valid and database is empty.

Definition at line 432 of file librpmDb.cc.

◆ size()

unsigned zypp::target::rpm::librpmDb::size ( ) const
Returns
Number of entries in the database (0 if not valid).

Definition at line 443 of file librpmDb.cc.

◆ dont_call_it()

void * zypp::target::rpm::librpmDb::dont_call_it ( ) const

Dont call it ;) It's for development and testing only.

Definition at line 461 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 474 of file librpmDb.cc.

◆ operator=()

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

◆ db_const_iterator() [1/2]

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

◆ db_const_iterator() [2/2]

zypp::target::rpm::librpmDb::db_const_iterator ( librpmDb::constPtr  dbptr_r = 0)

Constructor.

Iterator is initialized to findAll. The default form accesses librpmDb's default database. Explicitly providing a database handle should not be neccesary, except for testing.

◆ dbError()

shared_ptr<RpmException> zypp::target::rpm::librpmDb::dbError ( ) const

Return any database error.

NOTE: If the database gets blocked (see dbRelease) dbError will immediately report this, but an already running iteration will proceed to its end. Then the database is dropped.

◆ 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 402 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.

NOTE: No entry (false) migt be returned due to a meanwhile blocked database (see dbRelease). Use dbError to check this.

◆ 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 348 of file librpmDb.h.

◆ operator<<

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

Member Data Documentation

◆ _defaultRoot

Pathname zypp::target::rpm::librpmDb::_defaultRoot { "/" }
staticprivate

Current root directory for all operations.

(initially /)

Definition at line 67 of file librpmDb.h.

◆ _defaultDbPath

Pathname zypp::target::rpm::librpmDb::_defaultDbPath
staticprivate

Current directory (below root) that contains the rpmdb.

Definition at line 72 of file librpmDb.h.

◆ _rpmDefaultDbPath

Pathname zypp::target::rpm::librpmDb::_rpmDefaultDbPath
staticprivate

_dbpath configured in rpm config.

Definition at line 77 of file librpmDb.h.

◆ _defaultDb

librpmDb::constPtr zypp::target::rpm::librpmDb::_defaultDb
staticprivate

Current rpmdb handle.

Definition at line 82 of file librpmDb.h.

◆ ZYPP_API

bool _dbBlocked zypp::target::rpm::librpmDb::ZYPP_API
staticprivate

Whether access is blocked (no _defaultDb will be available).

Definition at line 87 of file librpmDb.h.

◆ _d

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

Definition at line 263 of file librpmDb.h.


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