22 #undef ZYPP_BASE_LOGGER_LOGGROUP 23 #define ZYPP_BASE_LOGGER_LOGGROUP "librpmDb" 41 D & operator=(
const D & );
63 ::addMacro( NULL,
"_dbpath", NULL, _dbPath.
asString().c_str(), RMIL_CMDLINE );
65 _ts = ::rpmtsCreate();
66 ::rpmtsSetRootDir( _ts,
_root.c_str() );
69 int res = ::rpmtsOpenDB( _ts, (readonly_r ? O_RDONLY : O_RDWR ));
72 ERR <<
"rpmdbOpen error(" << res <<
"): " << *
this << endl;
79 DBG <<
"DBACCESS " << *
this << endl;
99 Pathname librpmDb::_defaultRoot (
"/" );
105 const Pathname librpmDb::_defaultDbPath(
"/var/lib/rpm" );
107 bool librpmDb::_dbBlocked (
true );
115 bool librpmDb::globalInit()
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:" 146 std::string librpmDb::expand(
const std::string & macro_r )
148 if ( ! globalInit() )
151 char * val = ::rpmExpand( macro_r.c_str(), NULL );
169 if ( ! globalInit() )
178 ret =
new librpmDb( _defaultRoot, _defaultDbPath,
true );
201 if ( _defaultRoot == root_r )
212 PathInfo pi { root_r / _defaultDbPath };
213 if ( pi.isExist() && ! pi.isDir() ) {
215 excpt.addHistory(
str::Str() << pi );
219 _defaultRoot = root_r;
220 MIL <<
"Set new database location: " <<
stringPath( _defaultRoot, _defaultDbPath ) << endl;
231 void librpmDb::dbAccess()
241 _defaultDb = newLibrpmDb();
264 unsigned librpmDb::dbRelease(
bool force_r )
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;
286 _defaultDb->_d._error = shared_ptr<RpmAccessBlockedException>(
new RpmAccessBlockedException(_defaultDb->_d._root, _defaultDb->_d._dbPath));
301 unsigned librpmDb::blockAccess()
303 MIL <<
"Block access" << endl;
305 return dbRelease(
true );
314 void librpmDb::unblockAccess()
316 MIL <<
"Unblock access" << endl;
326 ostream & librpmDb::dumpState( ostream &
str )
330 return str <<
"[librpmDb " << (_dbBlocked?
"BLOCKED":
"CLOSED") <<
" " <<
stringPath( _defaultRoot, _defaultDbPath ) <<
"]";
332 return str <<
"[" << _defaultDb <<
"]";
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
#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.
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)
String related utilities and Regular expression matching.
bool findByRequiredBy(const std::string &tag_r)
Reset to iterate all packages that require a certain tag.
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 &)
Subclass to retrieve database content.
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.
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.
shared_ptr< RpmException > _dberr
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
friend ostream & operator<<(ostream &str, const D &obj)
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.
~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)
std::string stringPath(const Pathname &root_r, const Pathname &sub_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
TraitsType::constPtrType constPtr
friend std::ostream & operator<<(std::ostream &str, const ReferenceCounted &obj)
Stream output via dumpOn.