libzypp 17.31.23
librpmDb.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#ifndef librpmDb_h
13#define librpmDb_h
14
15#include <iosfwd>
16
17#include <zypp/base/ReferenceCounted.h>
18#include <zypp/base/NonCopyable.h>
19#include <zypp/base/PtrTypes.h>
20#include <zypp/PathInfo.h>
23
24namespace zypp
25{
26namespace target
27{
28namespace rpm
29{
30
32//
33// CLASS NAME : librpmDb
38{
39public:
40 typedef intrusive_ptr<librpmDb> Ptr;
41 typedef intrusive_ptr<const librpmDb> constPtr;
42private:
52 static void dbAccess( librpmDb::Ptr & ptr_r );
53
54public:
55
57 //
58 // static interface
59 //
61private:
62
68
73
78
83
87 static bool _dbBlocked;
88
96 static librpmDb * newLibrpmDb();
97
110 static void dbAccess();
111
112public:
113
120 static bool globalInit();
121
125 static std::string expand( const std::string & macro_r );
126
130 static std::string stringPath( const Pathname & root_r, const Pathname & sub_r )
131 {
132 return std::string( "'(" ) + root_r.asString() + ")" + sub_r.asString() + "'";
133 }
134
135public:
136
140 static const Pathname & defaultRoot()
141 {
142 return _defaultRoot;
143 }
144
148 static const Pathname & defaultDbPath()
149 {
150 return _defaultDbPath;
151 }
152
161 static Pathname suggestedDbPath( const Pathname & root_r );
162
177 static void dbAccess( const Pathname & root_r );
178
188 static void dbAccess( librpmDb::constPtr & ptr_r );
189
202 static unsigned dbRelease( bool force_r = false );
203
211 static unsigned blockAccess();
212
216 static unsigned blockAccess( const Pathname & root_r, const Pathname & dbPath_r )
217 {
218 return ( root_r == _defaultRoot && dbPath_r == _defaultDbPath ) ? blockAccess() : 0;
219 }
220
231 static void unblockAccess();
232
236 static bool isBlocked()
237 {
238 return _dbBlocked;
239 }
240
244 static std::ostream & dumpState( std::ostream & str );
245
246public:
247
251 class db_const_iterator;
252
253private:
255 //
256 // internal database handle interface (nonstatic)
257 //
259
263 class D;
264 D & _d;
265
266protected:
267
272 librpmDb( const Pathname & root_r, const Pathname & dbPath_r, bool readonly_r );
273
277 virtual void unref_to( unsigned refCount_r ) const;
278
279public:
280
284 virtual ~librpmDb();
285
289 const Pathname & root() const;
290
294 const Pathname & dbPath() const;
295
300 shared_ptr<RpmException> error() const;
301
305 bool valid() const
306 {
307 return( ! error() );
308 }
309
313 bool empty() const;
314
318 unsigned size() const;
319
320public:
321
325 void * dont_call_it() const;
326
330 virtual std::ostream & dumpOn( std::ostream & str ) const;
331};
332
334
336//
337// CLASS NAME : librpmDb::db_const_iterator
344{
345 db_const_iterator & operator=( const db_const_iterator & ); // NO ASSIGNMENT!
346 db_const_iterator ( const db_const_iterator & ); // NO COPY!
347 friend std::ostream & operator<<( std::ostream & str, const db_const_iterator & obj );
348 friend class librpmDb;
349
350private:
351
355 class D;
356 D & _d;
357
358public:
359
367
372
380 shared_ptr<RpmException> dbError() const;
381
385 void operator++();
386
391 unsigned dbHdrNum() const;
392
397 const RpmHeader::constPtr & operator*() const;
398
403 {
404 return operator*();
405 }
406
407public:
408
417 bool findAll();
418
422 bool findByFile( const std::string & file_r );
423
427 bool findByProvides( const std::string & tag_r );
428
432 bool findByRequiredBy( const std::string & tag_r );
433
437 bool findByConflicts( const std::string & tag_r );
438
449 bool findByName( const std::string & name_r );
450
451public:
452
460 bool findPackage( const std::string & name_r );
461
466 bool findPackage( const std::string & name_r, const Edition & ed_r );
467
471 bool findPackage( const Package::constPtr & which_r );
472};
473
475} //namespace rpm
476} //namespace target
477} // namespace zypp
478
479#endif // librpmDb_h
480
Edition represents [epoch:]version[-release]
Definition: Edition.h:61
TraitsType::constPtrType constPtr
Definition: Package.h:38
Base class for reference counted objects.
const std::string & asString() const
String representation.
Definition: Pathname.h:91
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:65
librpmDb internal database handle
Definition: librpmDb.cc:40
Subclass to retrieve database content.
Definition: librpmDb.h:344
unsigned dbHdrNum() const
Returns the current headers index in database, 0 if no header.
Definition: librpmDb.cc:670
bool findByProvides(const std::string &tag_r)
Reset to iterate all packages that provide a certain tag.
Definition: librpmDb.cc:743
bool findByName(const std::string &name_r)
Reset to iterate all packages with a certain name.
Definition: librpmDb.cc:776
db_const_iterator & operator=(const db_const_iterator &)
const RpmHeader::constPtr & operator->() const
Forwards to the current RpmHeader::constPtr.
Definition: librpmDb.h:402
bool findByFile(const std::string &file_r)
Reset to iterate all packages that own a certain file.
Definition: librpmDb.cc:732
bool findAll()
Reset to iterate all packages.
Definition: librpmDb.cc:721
const RpmHeader::constPtr & operator*() const
Returns the current RpmHeader::constPtr or NULL, if no more entries available.
Definition: librpmDb.cc:681
friend std::ostream & operator<<(std::ostream &str, const db_const_iterator &obj)
Definition: librpmDb.cc:706
bool findByRequiredBy(const std::string &tag_r)
Reset to iterate all packages that require a certain tag.
Definition: librpmDb.cc:754
bool findPackage(const std::string &name_r)
Find package by name.
Definition: librpmDb.cc:787
shared_ptr< RpmException > dbError() const
Return any database error.
Definition: librpmDb.cc:692
void operator++()
Advance to next RpmHeader::constPtr.
Definition: librpmDb.cc:659
bool findByConflicts(const std::string &tag_r)
Reset to iterate all packages that conflict with a certain tag.
Definition: librpmDb.cc:765
db_const_iterator(const db_const_iterator &)
Manage access to librpm database.
Definition: librpmDb.h:38
static bool _dbBlocked
Whether access is blocked (no _defaultDb will be available).
Definition: librpmDb.h:87
virtual void unref_to(unsigned refCount_r) const
Trigger from Rep, after refCount was decreased.
Definition: librpmDb.cc:385
static const Pathname & defaultDbPath()
Definition: librpmDb.h:148
static unsigned blockAccess(const Pathname &root_r, const Pathname &dbPath_r)
Definition: librpmDb.h:216
const Pathname & dbPath() const
Definition: librpmDb.cc:410
const Pathname & root() const
Definition: librpmDb.cc:399
static bool globalInit()
Initialize lib librpm (read configfiles etc.).
Definition: librpmDb.cc:111
virtual std::ostream & dumpOn(std::ostream &str) const
Dump debug info.
Definition: librpmDb.cc:474
static const Pathname & defaultRoot()
Definition: librpmDb.h:140
intrusive_ptr< const librpmDb > constPtr
Definition: librpmDb.h:41
intrusive_ptr< librpmDb > Ptr
Definition: librpmDb.h:40
unsigned size() const
Definition: librpmDb.cc:443
static std::string stringPath(const Pathname &root_r, const Pathname &sub_r)
Definition: librpmDb.h:130
static unsigned dbRelease(bool force_r=false)
If there are no outstanding references to the database (e.g.
Definition: librpmDb.cc:277
static std::ostream & dumpState(std::ostream &str)
Dump debug info.
Definition: librpmDb.cc:339
static librpmDb::constPtr _defaultDb
Current rpmdb handle.
Definition: librpmDb.h:82
shared_ptr< RpmException > error() const
Return any database error.
Definition: librpmDb.cc:421
static bool isBlocked()
Definition: librpmDb.h:236
static Pathname _rpmDefaultDbPath
_dbpath configured in rpm config.
Definition: librpmDb.h:77
static Pathname _defaultDbPath
Current directory (below root) that contains the rpmdb.
Definition: librpmDb.h:72
static librpmDb * newLibrpmDb()
For internal use.
Definition: librpmDb.cc:162
virtual ~librpmDb()
Destructor.
Definition: librpmDb.cc:374
void * dont_call_it() const
Dont call it ;) It's for development and testing only.
Definition: librpmDb.cc:461
static Pathname _defaultRoot
Current root directory for all operations.
Definition: librpmDb.h:67
static std::string expand(const std::string &macro_r)
Definition: librpmDb.cc:142
static void dbAccess(librpmDb::Ptr &ptr_r)
INTENTIONALLY UNDEFINED<\B> because of bug in Ptr classes which allows implicit conversion from librp...
static void dbAccess()
Access the database at the current default location.
Definition: librpmDb.cc:244
static unsigned blockAccess()
Blocks further access to rpmdb.
Definition: librpmDb.cc:314
static Pathname suggestedDbPath(const Pathname &root_r)
Definition: librpmDb.cc:190
static void unblockAccess()
Allow access to rpmdb e.g.
Definition: librpmDb.cc:327
String related utilities and Regular expression matching.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2