38 D & operator=(
const D & );
60 ::addMacro( NULL,
"_dbpath", NULL, _dbPath.
asString().c_str(), RMIL_CMDLINE );
62 _ts = ::rpmtsCreate();
63 ::rpmtsSetRootDir( _ts,
_root.c_str() );
67 if ( ! master.isFile() )
76 int res = ::rpmtsInitDB( _ts, 0644 );
79 ERR <<
"rpmdbInit error(" << res <<
"): " << *
this << endl;
87 int res = ::rpmtsOpenDB( _ts, (readonly_r ? O_RDONLY : O_RDWR ));
90 ERR <<
"rpmdbOpen error(" << res <<
"): " << *
this << endl;
97 DBG <<
"DBACCESS " << *
this << endl;
117 Pathname librpmDb::_defaultRoot (
"/" );
118 Pathname librpmDb::_defaultDbPath(
"/var/lib/rpm" );
120 bool librpmDb::_dbBlocked (
true );
128 bool librpmDb::globalInit()
130 static bool initialized =
false;
135 int rc = ::rpmReadConfigFiles( NULL, NULL );
138 ERR <<
"rpmReadConfigFiles returned " << rc << endl;
144 #define OUTVAL(n) << " (" #n ":" << expand( "%{" #n "}" ) << ")" 145 MIL <<
"librpm init done:" 159 std::string librpmDb::expand(
const std::string & macro_r )
161 if ( ! globalInit() )
164 char * val = ::rpmExpand( macro_r.c_str(), NULL );
188 if ( ! globalInit() )
197 ret =
new librpmDb( root_r, dbPath_r, readonly_r );
226 if ( _defaultRoot == root_r && _defaultDbPath == dbPath_r )
235 _defaultRoot = root_r;
236 _defaultDbPath = dbPath_r;
237 MIL <<
"Set new database location: " <<
stringPath( _defaultRoot, _defaultDbPath ) << endl;
248 void librpmDb::dbAccess()
258 _defaultDb = newLibrpmDb( _defaultRoot, _defaultDbPath,
true );
289 unsigned librpmDb::dbRelease(
bool force_r )
296 unsigned outstanding = _defaultDb->refCount() - 1;
298 switch ( outstanding )
303 DBG <<
"dbRelease: keep access, outstanding " << outstanding << endl;
308 DBG <<
"dbRelease: release" << (force_r && outstanding ?
"(forced)" :
"")
309 <<
", outstanding " << outstanding << endl;
311 _defaultDb->_d._error = shared_ptr<RpmAccessBlockedException>(
new RpmAccessBlockedException(_defaultDb->_d._root, _defaultDb->_d._dbPath));
326 unsigned librpmDb::blockAccess()
328 MIL <<
"Block access" << endl;
330 return dbRelease(
true );
339 void librpmDb::unblockAccess()
341 MIL <<
"Unblock access" << endl;
351 ostream & librpmDb::dumpState( ostream &
str )
355 return str <<
"[librpmDb " << (_dbBlocked?
"BLOCKED":
"CLOSED") <<
" " <<
stringPath( _defaultRoot, _defaultDbPath ) <<
"]";
357 return str <<
"[" << _defaultDb <<
"]";
375 : _d( * new
D( root_r, dbPath_r, readonly_r ) )
399 if ( refCount_r == 1 )
475 return rpmtsGetRdb(
_d.
_ts);
506 , _dbPath( dbPath_r )
511 ERR <<
"Relative path for root(" <<
_root <<
") or dbPath(" <<
_dbPath <<
")" << endl;
519 DBG << *
this << endl;
535 DBG << *
this << endl;
548 str <<
"ILLEGAL: '(" << obj.
root() <<
")" << obj.
dbPath() <<
"'";
552 str <<
"'(" << obj.
root() <<
")" << obj.
dbPath() <<
"':" << endl;
554 str <<
" V4: " << obj.
_dbV4 << endl;
555 str <<
" V3: " << obj.
_dbV3 << endl;
595 WAR <<
"No database access: " << _dberr << endl;
608 ::rpmdbFreeIterator( _mi );
616 bool create(
int rpmtag,
const void * keyp = NULL,
size_t keylen = 0 )
621 _mi = ::rpmtsInitIterator( _dbptr->_d._ts, rpmTag(rpmtag), keyp, keylen );
633 _mi = ::rpmdbFreeIterator( _mi );
636 if ( _dbptr && _dbptr->error() )
638 _dberr = _dbptr->error();
639 WAR <<
"Lost database access: " << _dberr << endl;
653 Header h = ::rpmdbNextIterator( _mi );
666 bool init(
int rpmtag,
const void * keyp = NULL,
size_t keylen = 0 )
668 if ( ! create( rpmtag, keyp, keylen ) )
677 bool set(
int off_r )
679 if ( ! create( RPMDBI_PACKAGES ) )
681 #warning TESTCASE: rpmdbAppendIterator and (non)sequential access? 682 #ifdef RPMFILEITERMAX // since rpm.4.12 683 ::rpmdbAppendIterator( _mi, (
const unsigned *)&off_r, 1 );
685 ::rpmdbAppendIterator( _mi, &off_r, 1 );
692 return( _mi ? ::rpmdbGetIteratorOffset( _mi ) : 0 );
699 int ret = ::rpmdbGetIteratorCount( _mi );
700 #warning TESTCASE: rpmdbGetIteratorCount returns 0 on sequential access? 701 return( ret ? ret : -1 );
720 :
_d( * new
D( dbptr_r ) )
778 return _d._dbptr->error();
791 str <<
"db_const_iterator(" << obj.
_d._dbptr
792 <<
" Size:" << obj.
_d.size()
793 <<
" HdrNum:" << obj.
_d.offset()
806 return _d.init( RPMDBI_PACKAGES );
817 return _d.init( RPMTAG_BASENAMES, file_r.c_str() );
828 return _d.init( RPMTAG_PROVIDENAME, tag_r.c_str() );
839 return _d.init( RPMTAG_REQUIRENAME, tag_r.c_str() );
850 return _d.init( RPMTAG_CONFLICTNAME, tag_r.c_str() );
861 return _d.init( RPMTAG_NAME, name_r.c_str() );
872 if ( !
_d.init( RPMTAG_NAME, name_r.c_str() ) )
875 if (
_d.size() == 1 )
881 for ( ; operator*(); operator++() )
883 if (
operator*()->tag_installtime() > itime )
886 itime = operator*()->tag_installtime();
890 return _d.set( match );
901 if ( !
_d.init( RPMTAG_NAME, name_r.c_str() ) )
904 for ( ; operator*(); operator++() )
906 if ( ed_r ==
operator*()->tag_edition() )
908 int match =
_d.offset();
909 return _d.set( match );
927 return findPackage( which_r->name(), which_r->edition() );
void * dont_call_it() const
Dont call it ;) It's for development and testing only.
PathInfo _dbV4
rpmV4 database (_dbDir/Packages)
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
const Pathname & dbPath() const
Directory that contains the rpmdb.
librpmDb::constPtr _dbptr
PathInfo _dbV3ToV4
rpmV3 database backup created on conversion to rpmV4 (_dbDir/packages.rpm3)
const Pathname & path() const
Return current Pathname.
std::string asString(const DefaultIntegral< Tp, TInitial > &obj)
#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.
Pathname _dbPath
Directory that contains the rpmdb.
shared_ptr< RpmException > _error
Collect info about what kind of rpmdb seems to be present by looking at paths and filenames...
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]
const Pathname & root() const
Root directory for all operations.
virtual void unref_to(unsigned refCount_r) const
Trigger from Rep, after refCount was decreased.
db_const_iterator(const db_const_iterator &)
DbDirInfo(const Pathname &root_r, const Pathname &dbPath_r)
For Constructor arguments see accessPath.
Subclass to retrieve database content.
virtual ~librpmDb()
Destructor.
#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.
bool findByName(const std::string &name_r)
Reset to iterate all packages with a certain name.
PathInfo _dbDir
database directory (unset on illegal constructor arguments)
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.
ReferenceCounted & operator=(const ReferenceCounted &)
Assignment.
Manage access to librpm database.
bool findPackage(const std::string &name_r)
Find package by name.
bool illegalArgs() const
Whether constructor arguments were illegal.
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.
Pathname _root
Root directory for all operations.
RpmHeader::constPtr _hptr
PathInfo _dbV3
rpmV3 database (_dbDir/packages.rpm)
void restat()
Restat all paths.
TraitsType::constPtrType constPtr
friend std::ostream & operator<<(std::ostream &str, const ReferenceCounted &obj)
Stream output via dumpOn.