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() );
70 if ( ! master.isFile() )
79 int res = ::rpmtsInitDB( _ts, 0644 );
82 ERR <<
"rpmdbInit error(" << res <<
"): " << *
this << endl;
90 int res = ::rpmtsOpenDB( _ts, (readonly_r ? O_RDONLY : O_RDWR ));
93 ERR <<
"rpmdbOpen error(" << res <<
"): " << *
this << endl;
100 DBG <<
"DBACCESS " << *
this << endl;
120 Pathname librpmDb::_defaultRoot (
"/" );
121 Pathname librpmDb::_defaultDbPath(
"/var/lib/rpm" );
123 bool librpmDb::_dbBlocked (
true );
131 bool librpmDb::globalInit()
133 static bool initialized =
false;
138 int rc = ::rpmReadConfigFiles( NULL, NULL );
141 ERR <<
"rpmReadConfigFiles returned " << rc << endl;
147 #define OUTVAL(n) << " (" #n ":" << expand( "%{" #n "}" ) << ")" 148 MIL <<
"librpm init done:" 162 std::string librpmDb::expand(
const std::string & macro_r )
164 if ( ! globalInit() )
167 char * val = ::rpmExpand( macro_r.c_str(), NULL );
191 if ( ! globalInit() )
200 ret =
new librpmDb( root_r, dbPath_r, readonly_r );
229 if ( _defaultRoot == root_r && _defaultDbPath == dbPath_r )
238 _defaultRoot = root_r;
239 _defaultDbPath = dbPath_r;
240 MIL <<
"Set new database location: " <<
stringPath( _defaultRoot, _defaultDbPath ) << endl;
251 void librpmDb::dbAccess()
261 _defaultDb = newLibrpmDb( _defaultRoot, _defaultDbPath,
true );
292 unsigned librpmDb::dbRelease(
bool force_r )
299 unsigned outstanding = _defaultDb->refCount() - 1;
301 switch ( outstanding )
306 DBG <<
"dbRelease: keep access, outstanding " << outstanding << endl;
311 DBG <<
"dbRelease: release" << (force_r && outstanding ?
"(forced)" :
"")
312 <<
", outstanding " << outstanding << endl;
314 _defaultDb->_d._error = shared_ptr<RpmAccessBlockedException>(
new RpmAccessBlockedException(_defaultDb->_d._root, _defaultDb->_d._dbPath));
329 unsigned librpmDb::blockAccess()
331 MIL <<
"Block access" << endl;
333 return dbRelease(
true );
342 void librpmDb::unblockAccess()
344 MIL <<
"Unblock access" << endl;
354 ostream & librpmDb::dumpState( ostream &
str )
358 return str <<
"[librpmDb " << (_dbBlocked?
"BLOCKED":
"CLOSED") <<
" " <<
stringPath( _defaultRoot, _defaultDbPath ) <<
"]";
360 return str <<
"[" << _defaultDb <<
"]";
378 : _d( * new
D( root_r, dbPath_r, readonly_r ) )
402 if ( refCount_r == 1 )
478 return rpmtsGetRdb(
_d.
_ts);
509 , _dbPath( dbPath_r )
514 ERR <<
"Relative path for root(" <<
_root <<
") or dbPath(" <<
_dbPath <<
")" << endl;
522 DBG << *
this << endl;
538 DBG << *
this << endl;
551 str <<
"ILLEGAL: '(" << obj.
root() <<
")" << obj.
dbPath() <<
"'";
555 str <<
"'(" << obj.
root() <<
")" << obj.
dbPath() <<
"':" << endl;
557 str <<
" V4: " << obj.
_dbV4 << endl;
558 str <<
" V3: " << obj.
_dbV3 << endl;
598 WAR <<
"No database access: " << _dberr << endl;
611 ::rpmdbFreeIterator( _mi );
619 bool create(
int rpmtag,
const void * keyp = NULL,
size_t keylen = 0 )
624 _mi = ::rpmtsInitIterator( _dbptr->_d._ts, rpmTag(rpmtag), keyp, keylen );
636 _mi = ::rpmdbFreeIterator( _mi );
639 if ( _dbptr && _dbptr->error() )
641 _dberr = _dbptr->error();
642 WAR <<
"Lost database access: " << _dberr << endl;
656 Header h = ::rpmdbNextIterator( _mi );
669 bool init(
int rpmtag,
const void * keyp = NULL,
size_t keylen = 0 )
671 if ( ! create( rpmtag, keyp, keylen ) )
682 if ( ! create( RPMDBI_PACKAGES ) )
684 #warning TESTCASE: rpmdbAppendIterator and (non)sequential access? 685 #ifdef RPMFILEITERMAX // since rpm.4.12 686 ::rpmdbAppendIterator( _mi, (
const unsigned *)&off_r, 1 );
688 ::rpmdbAppendIterator( _mi, &off_r, 1 );
695 return( _mi ? ::rpmdbGetIteratorOffset( _mi ) : 0 );
702 int ret = ::rpmdbGetIteratorCount( _mi );
703 #warning TESTCASE: rpmdbGetIteratorCount returns 0 on sequential access? 704 return( ret ? ret : -1 );
723 :
_d( * new
D( dbptr_r ) )
781 return _d._dbptr->error();
794 str <<
"db_const_iterator(" << obj.
_d._dbptr
795 <<
" Size:" << obj.
_d.size()
796 <<
" HdrNum:" << obj.
_d.offset()
809 return _d.init( RPMDBI_PACKAGES );
820 return _d.init( RPMTAG_BASENAMES, file_r.c_str() );
831 return _d.init( RPMTAG_PROVIDENAME, tag_r.c_str() );
842 return _d.init( RPMTAG_REQUIRENAME, tag_r.c_str() );
853 return _d.init( RPMTAG_CONFLICTNAME, tag_r.c_str() );
864 return _d.init( RPMTAG_NAME, name_r.c_str() );
875 if ( !
_d.init( RPMTAG_NAME, name_r.c_str() ) )
878 if (
_d.size() == 1 )
884 for ( ; operator*(); operator++() )
886 if (
operator*()->tag_installtime() > itime )
889 itime = operator*()->tag_installtime();
893 return _d.set( match );
904 if ( !
_d.init( RPMTAG_NAME, name_r.c_str() ) )
907 for ( ; operator*(); operator++() )
909 if ( ed_r ==
operator*()->tag_edition() )
911 int match =
_d.offset();
912 return _d.set( match );
930 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
bool set(int off_r)
Create an itertator that contains the database entry located at off_r, and advance to the 1st header.
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.