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;
93 D (
const D & ) =
delete;
107 :
_root { std::move(root_r) }
108 ,
_dbPath { std::move(dbPath_r) }
121 int res = ::rpmtsOpenDB(
_ts, (readonly_r ? O_RDONLY : O_RDWR ) );
123 ERR <<
"rpmdbOpen error(" << res <<
"): " << *
this << endl;
130 { ::addMacro( NULL,
"_dbpath", NULL, dppath_r.
asString().c_str(), RMIL_CMDLINE ); }
140 static bool initialized =
false;
145 int rc = ::rpmReadConfigFiles( NULL, NULL );
148 ERR <<
"rpmReadConfigFiles returned " << rc << endl;
165 return std::string( val );
167 return std::string();
195 {
return dbAccess( root_r, dbPath_r,
false ); }
198 {
return dbAccess( root_r, dbPath_r,
true ); }
212 if ( not create_r && not
dbExists ) {
227 : _d( * new
D( root_r, dbPath_r, readonly_r ) )
232 MIL <<
"Close database " << *
this << endl;
252 class librpmDb::db_const_iterator::D
255 D (
const D & ) =
delete;
279 WAR <<
"No database access: " <<
dumpPath( root_r, dbPath_r ) << endl;
287 bool create(
int rpmtag,
const void * keyp = NULL,
size_t keylen = 0 )
314 Header h = ::rpmdbNextIterator(
_mi );
327 bool init(
int rpmtag,
const void * keyp = NULL,
size_t keylen = 0 )
329 if ( !
create( rpmtag, keyp, keylen ) )
338 bool set(
int off_r )
340 if ( !
create( RPMDBI_PACKAGES ) )
342 #ifdef RPMFILEITERMAX // since rpm.4.12 343 ::rpmdbAppendIterator(
_mi, (
const unsigned *)&off_r, 1 );
345 ::rpmdbAppendIterator(
_mi, &off_r, 1 );
352 return(
_mi ? ::rpmdbGetIteratorOffset(
_mi ) : 0 );
359 int ret = ::rpmdbGetIteratorCount(
_mi );
360 return( ret ? ret : -1 );
380 librpmDb::db_const_iterator::db_const_iterator()
381 :
_d( * new D(
"/" ) )
384 librpmDb::db_const_iterator::db_const_iterator(
const Pathname & root_r )
385 :
_d( * new D( root_r ) )
388 librpmDb::db_const_iterator::db_const_iterator(
const Pathname & root_r,
const Pathname & dbPath_r )
389 :
_d( * new D( root_r, dbPath_r ) )
392 librpmDb::db_const_iterator::db_const_iterator( std::nullptr_t )
396 librpmDb::db_const_iterator::~db_const_iterator()
399 bool librpmDb::db_const_iterator::hasDB()
const 402 void librpmDb::db_const_iterator::operator++()
405 unsigned librpmDb::db_const_iterator::dbHdrNum()
const 412 {
return str <<
"db_const_iterator(" << obj._d._dbptr <<
")"; }
414 bool librpmDb::db_const_iterator::findAll()
415 {
return _d.
init( RPMDBI_PACKAGES ); }
417 bool librpmDb::db_const_iterator::findByFile(
const std::string & file_r )
418 {
return _d.
init( RPMTAG_BASENAMES, file_r.c_str() ); }
420 bool librpmDb::db_const_iterator::findByProvides(
const std::string & tag_r )
421 {
return _d.
init( RPMTAG_PROVIDENAME, tag_r.c_str() ); }
423 bool librpmDb::db_const_iterator::findByRequiredBy(
const std::string & tag_r )
424 {
return _d.
init( RPMTAG_REQUIRENAME, tag_r.c_str() ); }
426 bool librpmDb::db_const_iterator::findByConflicts(
const std::string & tag_r )
427 {
return _d.
init( RPMTAG_CONFLICTNAME, tag_r.c_str() ); }
429 bool librpmDb::db_const_iterator::findByName(
const std::string & name_r )
430 {
return _d.
init( RPMTAG_NAME, name_r.c_str() ); }
432 bool librpmDb::db_const_iterator::findPackage(
const std::string & name_r )
434 if ( !
_d.
init( RPMTAG_NAME, name_r.c_str() ) )
445 if (
operator*()->tag_installtime() > itime )
452 return _d.
set( match );
455 bool librpmDb::db_const_iterator::findPackage(
const std::string & name_r,
const Edition & ed_r )
457 if ( !
_d.
init( RPMTAG_NAME, name_r.c_str() ) )
462 if ( ed_r ==
operator*()->tag_edition() )
465 return _d.
set( match );
472 bool librpmDb::db_const_iterator::findPackage(
const Package::constPtr & which_r )
477 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()