16 #include <zypp/base/Logger.h> 17 #include <zypp/PathInfo.h> 22 #undef ZYPP_BASE_LOGGER_LOGGROUP 23 #define ZYPP_BASE_LOGGER_LOGGROUP "librpmDb" 63 ::addMacro( NULL,
"_dbpath", NULL,
_dbPath.
asString().c_str(), RMIL_CMDLINE );
65 _ts = ::rpmtsCreate();
69 int res = ::rpmtsOpenDB(
_ts, (readonly_r ? O_RDONLY : O_RDWR ));
72 ERR <<
"rpmdbOpen error(" << res <<
"): " << *
this << endl;
79 DBG <<
"DBACCESS " << *
this << endl;
113 static bool initialized =
false;
118 int rc = ::rpmReadConfigFiles( NULL, NULL );
121 ERR <<
"rpmReadConfigFiles returned " << rc << endl;
147 char * val = ::rpmExpand( macro_r.c_str(), NULL );
151 std::string ret( val );
201 for (
auto p : {
"/var/lib/rpm",
"/usr/lib/sysimage/rpm" } ) {
203 MIL <<
"Suggest existing database at " <<
stringPath( root_r, p ) << endl;
284 unsigned outstanding =
_defaultDb->refCount() - 1;
286 switch ( outstanding )
291 DBG <<
"dbRelease: keep access, outstanding " << outstanding << endl;
296 DBG <<
"dbRelease: release" << (force_r && outstanding ?
"(forced)" :
"")
297 <<
", outstanding " << outstanding << endl;
316 MIL <<
"Block access" << endl;
329 MIL <<
"Unblock access" << endl;
363 : _d( * new
D( root_r, dbPath_r, readonly_r ) )
387 if ( refCount_r == 1 )
463 return rpmtsGetRdb(
_d.
_ts);
514 WAR <<
"No database access: " <<
_dberr << endl;
527 ::rpmdbFreeIterator(
_mi );
535 bool create(
int rpmtag,
const void * keyp = NULL,
size_t keylen = 0 )
540 _mi = ::rpmtsInitIterator(
_dbptr->_d._ts, rpmTag(rpmtag), keyp, keylen );
552 _mi = ::rpmdbFreeIterator(
_mi );
558 WAR <<
"Lost database access: " <<
_dberr << endl;
572 Header h = ::rpmdbNextIterator(
_mi );
585 bool init(
int rpmtag,
const void * keyp = NULL,
size_t keylen = 0 )
587 if ( !
create( rpmtag, keyp, keylen ) )
596 bool set(
int off_r )
598 if ( !
create( RPMDBI_PACKAGES ) )
600 #ifdef RPMFILEITERMAX // since rpm.4.12 601 ::rpmdbAppendIterator(
_mi, (
const unsigned *)&off_r, 1 );
603 ::rpmdbAppendIterator(
_mi, &off_r, 1 );
610 return(
_mi ? ::rpmdbGetIteratorOffset(
_mi ) : 0 );
617 int ret = ::rpmdbGetIteratorCount(
_mi );
618 return( ret ? ret : -1 );
637 : _d( * new
D( dbptr_r ) )
695 return _d._dbptr->error();
708 str <<
"db_const_iterator(" << obj.
_d._dbptr
709 <<
" Size:" << obj.
_d.size()
710 <<
" HdrNum:" << obj.
_d.offset()
723 return _d.init( RPMDBI_PACKAGES );
734 return _d.init( RPMTAG_BASENAMES, file_r.c_str() );
745 return _d.init( RPMTAG_PROVIDENAME, tag_r.c_str() );
756 return _d.init( RPMTAG_REQUIRENAME, tag_r.c_str() );
767 return _d.init( RPMTAG_CONFLICTNAME, tag_r.c_str() );
778 return _d.init( RPMTAG_NAME, name_r.c_str() );
789 if ( !
_d.init( RPMTAG_NAME, name_r.c_str() ) )
792 if (
_d.size() == 1 )
798 for ( ; operator*(); operator++() )
800 if (
operator*()->tag_installtime() > itime )
803 itime = operator*()->tag_installtime();
807 return _d.set( match );
818 if ( !
_d.init( RPMTAG_NAME, name_r.c_str() ) )
821 for ( ; operator*(); operator++() )
823 if ( ed_r ==
operator*()->tag_edition() )
825 int match =
_d.offset();
826 return _d.set( match );
844 return findPackage( which_r->name(), which_r->edition() );
void * dont_call_it() const
Dont call it ;) It's for development and testing only.
librpmDb::constPtr _dbptr
static bool _dbBlocked
Whether access is blocked (no _defaultDb will be available).
static unsigned blockAccess()
Blocks further access to rpmdb.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
void operator++()
Advance to next RpmHeader::constPtr.
bool findByProvides(const std::string &tag_r)
Reset to iterate all packages that provide a certain tag.
static std::string expand(const std::string ¯o_r)
bool advance()
Advance to the first/next header in iterator.
shared_ptr< RpmException > _error
static void dbAccess()
Access the database at the current default location.
const char * c_str() const
String representation.
String related utilities and Regular expression matching.
bool findByRequiredBy(const std::string &tag_r)
Reset to iterate all packages that require a certain tag.
librpmDb(const Pathname &root_r, const Pathname &dbPath_r, bool readonly_r)
Private constructor! librpmDb objects are to be created via static interface only.
Edition represents [epoch:]version[-release]
virtual void unref_to(unsigned refCount_r) const
Trigger from Rep, after refCount was decreased.
db_const_iterator(const db_const_iterator &)
friend std::ostream & operator<<(std::ostream &str, const D &obj)
Subclass to retrieve database content.
static librpmDb::constPtr _defaultDb
Current rpmdb handle.
static librpmDb * newLibrpmDb()
For internal use.
virtual ~librpmDb()
Destructor.
bool empty() const
Test for an empty path.
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
shared_ptr< RpmException > dbError() const
Return any database error.
const std::string & asString() const
String representation.
static Pathname _rpmDefaultDbPath
_dbpath configured in rpm config.
static Pathname _defaultRoot
Current root directory for all operations.
bool findByName(const std::string &name_r)
Reset to iterate all packages with a certain name.
static unsigned dbRelease(bool force_r=false)
If there are no outstanding references to the database (e.g.
shared_ptr< RpmException > error() const
Return any database error.
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
bool absolute() const
Test for an absolute path.
bool findByFile(const std::string &file_r)
Reset to iterate all packages that own a certain file.
const Pathname & root() const
Just inherits Exception to separate media exceptions.
Manage access to librpm database.
bool findPackage(const std::string &name_r)
Find package by name.
static void unblockAccess()
Allow access to rpmdb e.g.
shared_ptr< RpmException > _dberr
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
static Pathname _defaultDbPath
Current directory (below root) that contains the rpmdb.
bool findAll()
Reset to iterate all packages.
D(librpmDb::constPtr dbptr_r)
librpmDb internal database handle
const RpmHeader::constPtr & operator*() const
Returns the current RpmHeader::constPtr or NULL, if no more entries available.
static bool globalInit()
Initialize lib librpm (read configfiles etc.).
~db_const_iterator()
Destructor.
bool findByConflicts(const std::string &tag_r)
Reset to iterate all packages that conflict with a certain tag.
Wrapper class for ::stat/::lstat.
D(const Pathname &root_r, const Pathname &dbPath_r, bool readonly_r)
virtual std::ostream & dumpOn(std::ostream &str) const
Dump debug info.
unsigned dbHdrNum() const
Returns the current headers index in database, 0 if no header.
const Pathname & dbPath() const
bool destroy()
Destroy iterator.
bool init(int rpmtag, const void *keyp=NULL, size_t keylen=0)
Access a dbindex file and advance to the 1st header.
intrusive_ptr< const librpmDb > constPtr
Easy-to use interface to the ZYPP dependency resolver.
static Pathname suggestedDbPath(const Pathname &root_r)
bool create(int rpmtag, const void *keyp=NULL, size_t keylen=0)
Let iterator access a dbindex file.
RpmHeader::constPtr _hptr
static std::ostream & dumpState(std::ostream &str)
Dump debug info.
static std::string stringPath(const Pathname &root_r, const Pathname &sub_r)
TraitsType::constPtrType constPtr
friend std::ostream & operator<<(std::ostream &str, const ReferenceCounted &obj)
Stream output via dumpOn.