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;
117 static bool initialized =
false;
122 int rc = ::rpmReadConfigFiles( NULL, NULL );
125 ERR <<
"rpmReadConfigFiles returned " << rc << endl;
131 #define OUTVAL(n) << " (" #n ":" << expand( "%{" #n "}" ) << ")" 132 MIL <<
"librpm init done:" 151 char * val = ::rpmExpand( macro_r.c_str(), NULL );
155 std::string ret( val );
213 if ( pi.isExist() && ! pi.isDir() ) {
215 excpt.addHistory(
str::Str() << pi );
271 unsigned outstanding =
_defaultDb->refCount() - 1;
273 switch ( outstanding )
278 DBG <<
"dbRelease: keep access, outstanding " << outstanding << endl;
283 DBG <<
"dbRelease: release" << (force_r && outstanding ?
"(forced)" :
"")
284 <<
", outstanding " << outstanding << endl;
303 MIL <<
"Block access" << endl;
316 MIL <<
"Unblock access" << endl;
350 : _d( * new
D( root_r, dbPath_r, readonly_r ) )
374 if ( refCount_r == 1 )
450 return rpmtsGetRdb(
_d.
_ts);
501 WAR <<
"No database access: " <<
_dberr << endl;
514 ::rpmdbFreeIterator(
_mi );
522 bool create(
int rpmtag,
const void * keyp = NULL,
size_t keylen = 0 )
527 _mi = ::rpmtsInitIterator(
_dbptr->_d._ts, rpmTag(rpmtag), keyp, keylen );
539 _mi = ::rpmdbFreeIterator(
_mi );
545 WAR <<
"Lost database access: " <<
_dberr << endl;
559 Header h = ::rpmdbNextIterator(
_mi );
572 bool init(
int rpmtag,
const void * keyp = NULL,
size_t keylen = 0 )
574 if ( !
create( rpmtag, keyp, keylen ) )
583 bool set(
int off_r )
585 if ( !
create( RPMDBI_PACKAGES ) )
587 #warning TESTCASE: rpmdbAppendIterator and (non)sequential access? 588 #ifdef RPMFILEITERMAX // since rpm.4.12 589 ::rpmdbAppendIterator(
_mi, (
const unsigned *)&off_r, 1 );
591 ::rpmdbAppendIterator(
_mi, &off_r, 1 );
598 return(
_mi ? ::rpmdbGetIteratorOffset(
_mi ) : 0 );
605 int ret = ::rpmdbGetIteratorCount(
_mi );
606 #warning TESTCASE: rpmdbGetIteratorCount returns 0 on sequential access? 607 return( ret ? ret : -1 );
626 : _d( * new
D( dbptr_r ) )
684 return _d._dbptr->error();
697 str <<
"db_const_iterator(" << obj.
_d._dbptr
698 <<
" Size:" << obj.
_d.size()
699 <<
" HdrNum:" << obj.
_d.offset()
712 return _d.init( RPMDBI_PACKAGES );
723 return _d.init( RPMTAG_BASENAMES, file_r.c_str() );
734 return _d.init( RPMTAG_PROVIDENAME, tag_r.c_str() );
745 return _d.init( RPMTAG_REQUIRENAME, tag_r.c_str() );
756 return _d.init( RPMTAG_CONFLICTNAME, tag_r.c_str() );
767 return _d.init( RPMTAG_NAME, name_r.c_str() );
778 if ( !
_d.init( RPMTAG_NAME, name_r.c_str() ) )
781 if (
_d.size() == 1 )
787 for ( ; operator*(); operator++() )
789 if (
operator*()->tag_installtime() > itime )
792 itime = operator*()->tag_installtime();
796 return _d.set( match );
807 if ( !
_d.init( RPMTAG_NAME, name_r.c_str() ) )
810 for ( ; operator*(); operator++() )
812 if ( ed_r ==
operator*()->tag_edition() )
814 int match =
_d.offset();
815 return _d.set( match );
833 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.
std::ostream & dumpOn(std::ostream &str, const zypp::shared_ptr< void > &obj)
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.
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
const std::string & asString() const
String representation.
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.
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).
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.
static const Pathname _defaultDbPath
Current directory (below root) that contains the rpmdb.
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.
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.