libzypp  17.30.0
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 
24 namespace zypp
25 {
26 namespace target
27 {
28 namespace rpm
29 {
30 
32 //
33 // CLASS NAME : librpmDb
38 {
39 public:
40  typedef intrusive_ptr<librpmDb> Ptr;
41  typedef intrusive_ptr<const librpmDb> constPtr;
42 private:
52  static void dbAccess( librpmDb::Ptr & ptr_r );
53 
54 public:
55 
57  //
58  // static interface
59  //
61 private:
62 
68 
73 
78 
83 
87  static bool _dbBlocked;
88 
96  static librpmDb * newLibrpmDb();
97 
110  static void dbAccess();
111 
112 public:
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 
135 public:
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 
223  static void unblockAccess();
224 
228  static bool isBlocked()
229  {
230  return _dbBlocked;
231  }
232 
236  static std::ostream & dumpState( std::ostream & str );
237 
238 public:
239 
243  class db_const_iterator;
244 
245 private:
247  //
248  // internal database handle interface (nonstatic)
249  //
251 
255  class D;
256  D & _d;
257 
258 protected:
259 
264  librpmDb( const Pathname & root_r, const Pathname & dbPath_r, bool readonly_r );
265 
269  virtual void unref_to( unsigned refCount_r ) const;
270 
271 public:
272 
276  virtual ~librpmDb();
277 
281  const Pathname & root() const;
282 
286  const Pathname & dbPath() const;
287 
292  shared_ptr<RpmException> error() const;
293 
297  bool valid() const
298  {
299  return( ! error() );
300  }
301 
305  bool empty() const;
306 
310  unsigned size() const;
311 
312 public:
313 
317  void * dont_call_it() const;
318 
322  virtual std::ostream & dumpOn( std::ostream & str ) const;
323 };
324 
326 
328 //
329 // CLASS NAME : librpmDb::db_const_iterator
336 {
337  db_const_iterator & operator=( const db_const_iterator & ); // NO ASSIGNMENT!
338  db_const_iterator ( const db_const_iterator & ); // NO COPY!
339  friend std::ostream & operator<<( std::ostream & str, const db_const_iterator & obj );
340  friend class librpmDb;
341 
342 private:
343 
347  class D;
348  D & _d;
349 
350 public:
351 
358  db_const_iterator( librpmDb::constPtr dbptr_r = 0 );
359 
364 
372  shared_ptr<RpmException> dbError() const;
373 
377  void operator++();
378 
383  unsigned dbHdrNum() const;
384 
389  const RpmHeader::constPtr & operator*() const;
390 
395  {
396  return operator*();
397  }
398 
399 public:
400 
409  bool findAll();
410 
414  bool findByFile( const std::string & file_r );
415 
419  bool findByProvides( const std::string & tag_r );
420 
424  bool findByRequiredBy( const std::string & tag_r );
425 
429  bool findByConflicts( const std::string & tag_r );
430 
441  bool findByName( const std::string & name_r );
442 
443 public:
444 
452  bool findPackage( const std::string & name_r );
453 
458  bool findPackage( const std::string & name_r, const Edition & ed_r );
459 
463  bool findPackage( const Package::constPtr & which_r );
464 };
465 
467 } //namespace rpm
468 } //namespace target
469 } // namespace zypp
470 
471 #endif // librpmDb_h
472 
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:336
unsigned dbHdrNum() const
Returns the current headers index in database, 0 if no header.
Definition: librpmDb.cc:670
db_const_iterator & operator=(const db_const_iterator &)
bool findByProvides(const std::string &tag_r)
Reset to iterate all packages that provide a certain tag.
Definition: librpmDb.cc:743
friend std::ostream & operator<<(std::ostream &str, const db_const_iterator &obj)
Definition: librpmDb.cc:706
bool findByName(const std::string &name_r)
Reset to iterate all packages with a certain name.
Definition: librpmDb.cc:776
const RpmHeader::constPtr & operator->() const
Forwards to the current RpmHeader::constPtr.
Definition: librpmDb.h:394
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
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 const Pathname & defaultDbPath()
Definition: librpmDb.h:148
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
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:228
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...
librpmDb(const Pathname &root_r, const Pathname &dbPath_r, bool readonly_r)
Private constructor! librpmDb objects are to be created via static interface only.
Definition: librpmDb.cc:362
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