24 #undef ZYPP_BASE_LOGGER_LOGGROUP 25 #define ZYPP_BASE_LOGGER_LOGGROUP "librpmDb" 44 ret =
"/usr/lib/sysimage/rpm";
45 WAR <<
"Looks like rpm has no %{_dbpath} set!?! Assuming " << ret << endl;
56 for (
auto p : {
"/var/lib/rpm",
"/usr/lib/sysimage/rpm" } ) {
58 MIL <<
"Suggest existing database at " <<
dumpPath( root_r, p ) << endl;
64 MIL <<
"Suggest rpm dbpath " <<
dumpPath( root_r, defaultDbPath ) << endl;
94 D (
const D & ) =
delete;
108 :
_root { std::move(root_r) }
109 ,
_dbPath { std::move(dbPath_r) }
122 int res = ::rpmtsOpenDB(
_ts, (readonly_r ? O_RDONLY : O_RDWR ) );
124 ERR <<
"rpmdbOpen error(" << res <<
"): " << *
this << endl;
131 { ::addMacro( NULL,
"_dbpath", NULL, dppath_r.
asString().c_str(), RMIL_CMDLINE ); }
141 static bool initialized =
false;
146 int rc = ::rpmReadConfigFiles( NULL, NULL );
149 ERR <<
"rpmReadConfigFiles returned " << rc << endl;
166 return std::string( val );
168 return std::string();
196 {
return dbAccess( root_r, dbPath_r,
false ); }
199 {
return dbAccess( root_r, dbPath_r,
true ); }
213 if ( not create_r && not
dbExists ) {
228 : _d( * new
D( root_r, dbPath_r, readonly_r ) )
233 MIL <<
"Close database " << *
this << endl;
253 class librpmDb::db_const_iterator::D
256 D (
const D & ) =
delete;
280 WAR <<
"No database access: " <<
dumpPath( root_r, dbPath_r ) << endl;
288 bool create(
int rpmtag,
const void * keyp = NULL,
size_t keylen = 0 )
315 Header h = ::rpmdbNextIterator(
_mi );
328 bool init(
int rpmtag,
const void * keyp = NULL,
size_t keylen = 0 )
330 if ( !
create( rpmtag, keyp, keylen ) )
339 bool set(
int off_r )
341 if ( !
create( RPMDBI_PACKAGES ) )
343 #ifdef RPMFILEITERMAX // since rpm.4.12 344 ::rpmdbAppendIterator(
_mi, (
const unsigned *)&off_r, 1 );
346 ::rpmdbAppendIterator(
_mi, &off_r, 1 );
353 return(
_mi ? ::rpmdbGetIteratorOffset(
_mi ) : 0 );
360 int ret = ::rpmdbGetIteratorCount(
_mi );
361 return( ret ? ret : -1 );
381 librpmDb::db_const_iterator::db_const_iterator()
382 :
_d( * new D(
"/" ) )
385 librpmDb::db_const_iterator::db_const_iterator(
const Pathname & root_r )
386 :
_d( * new D( root_r ) )
389 librpmDb::db_const_iterator::db_const_iterator(
const Pathname & root_r,
const Pathname & dbPath_r )
390 :
_d( * new D( root_r, dbPath_r ) )
393 librpmDb::db_const_iterator::db_const_iterator( std::nullptr_t )
397 librpmDb::db_const_iterator::~db_const_iterator()
400 bool librpmDb::db_const_iterator::hasDB()
const 403 void librpmDb::db_const_iterator::operator++()
406 unsigned librpmDb::db_const_iterator::dbHdrNum()
const 413 {
return str <<
"db_const_iterator(" << obj._d._dbptr <<
")"; }
415 bool librpmDb::db_const_iterator::findAll()
416 {
return _d.
init( RPMDBI_PACKAGES ); }
418 bool librpmDb::db_const_iterator::findByFile(
const std::string & file_r )
419 {
return _d.
init( RPMTAG_BASENAMES, file_r.c_str() ); }
421 bool librpmDb::db_const_iterator::findByProvides(
const std::string & tag_r )
422 {
return _d.
init( RPMTAG_PROVIDENAME, tag_r.c_str() ); }
424 bool librpmDb::db_const_iterator::findByRequiredBy(
const std::string & tag_r )
425 {
return _d.
init( RPMTAG_REQUIRENAME, tag_r.c_str() ); }
427 bool librpmDb::db_const_iterator::findByConflicts(
const std::string & tag_r )
428 {
return _d.
init( RPMTAG_CONFLICTNAME, tag_r.c_str() ); }
430 bool librpmDb::db_const_iterator::findByName(
const std::string & name_r )
431 {
return _d.
init( RPMTAG_NAME, name_r.c_str() ); }
433 bool librpmDb::db_const_iterator::findPackage(
const std::string & name_r )
435 if ( !
_d.
init( RPMTAG_NAME, name_r.c_str() ) )
446 if (
operator*()->tag_installtime() > itime )
453 return _d.
set( match );
456 bool librpmDb::db_const_iterator::findPackage(
const std::string & name_r,
const Edition & ed_r )
458 if ( !
_d.
init( RPMTAG_NAME, name_r.c_str() ) )
463 if ( ed_r ==
operator*()->tag_edition() )
466 return _d.
set( match );
473 bool librpmDb::db_const_iterator::findPackage(
const Package::constPtr & which_r )
478 return findPackage( which_r->name(), which_r->edition() );
static void macroResetDbpath()
TraitsType::constPtrType constPtr
librpmDb::constPtr _dbptr
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
static std::string expand(const std::string ¯o_r)
bool advance()
Advance to the first/next header in iterator.
void reset()
Reset to default Ctor values.
bool set(int off_r)
Create an itertator that contains the database entry located at off_r, and advance to the 1st header...
const char * c_str() const
String representation.
String related utilities and Regular expression matching.
bool findPackage(const std::string &name_r)
Find package by name.
const RpmHeader::constPtr & operator*() const
Returns the current RpmHeader::constPtr or NULL, if no more entries available.
static bool dbExists(const Pathname &root_r, const Pathname &dbPath_r=Pathname())
static librpmDb::constPtr dbOpenCreate(const Pathname &root_r, const Pathname &dbPath_r=Pathname())
Assert the rpmdb below the system at root_r exists.
static void macroSetDbpath(const Pathname &dppath_r)
D & operator=(const D &)=delete
~librpmDb() override
Destructor.
friend std::ostream & operator<<(std::ostream &str, const D &obj)
D(const Pathname &root_r, const Pathname &dbPath_r=Pathname())
Open a specific rpmdb if it exists.
std::ostream & dumpOn(std::ostream &str) const override
Dump debug info.
_dumpPath dumpPath(const Pathname &root_r, const Pathname &sub_r)
dumpPath iomaip to dump '(root_r)sub_r' output,
friend std::ostream & operator<<(std::ostream &str, const db_const_iterator &obj)
bool empty() const
Test for an empty path.
bool findAll()
Reset to iterate all packages.
Subclass to retrieve rpm database content.
const std::string & asString() const
String representation.
Pathname suggestedDbPath(const Pathname &root_r)
bool dbExists(const Pathname &root_r, const Pathname &dbPath_r)
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
bool absolute() const
Test for an absolute path.
const Pathname & root() const
Just inherits Exception to separate media exceptions.
static librpmDb::constPtr dbOpenIf(const Pathname &root_r, const Pathname &dbPath_r=Pathname())
Open the rpmdb below the system at root_r (if it exists).
D(Pathname root_r, Pathname dbPath_r, bool readonly_r)
void setDispose(const Dispose &dispose_r)
Set a new dispose function.
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
void unref_to(unsigned refCount_r) const override
Trigger from Rep, after refCount was decreased.
librpmDb internal database handle
AutoDispose< rpmdbMatchIterator > _mi
static bool globalInit()
Initialize lib librpm (read configfiles etc.).
D & operator=(const D &)=delete
Wrapper class for ::stat/::lstat.
Pathname sanitizedDbPath(const Pathname &root_r, const Pathname &dbPath_r)
static void dbAccess(librpmDb::Ptr &ptr_r)
INTENTIONALLY UNDEFINED<> because of bug in Ptr classes which allows implicit conversion from librpmD...
const Pathname & dbPath() const
bool destroy()
Reset 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
void operator++()
Advance to next RpmHeader::constPtr.
const Pathname & rpmDefaultDbPath()