libzypp  17.31.31
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 
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 
246 public:
247 
251  class db_const_iterator;
252 
253 private:
255  //
256  // internal database handle interface (nonstatic)
257  //
259 
263  class D;
264  D & _d;
265 
266 protected:
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 
279 public:
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 
320 public:
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 
350 private:
351 
355  class D;
356  D & _d;
357 
358 public:
359 
366  db_const_iterator( librpmDb::constPtr dbptr_r = 0 );
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 
407 public:
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 
451 public:
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 
void * dont_call_it() const
Dont call it ;) It&#39;s for development and testing only.
Definition: librpmDb.cc:461
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:65
static const Pathname & defaultRoot()
Definition: librpmDb.h:140
static bool _dbBlocked
Whether access is blocked (no _defaultDb will be available).
Definition: librpmDb.h:87
static unsigned blockAccess()
Blocks further access to rpmdb.
Definition: librpmDb.cc:314
friend std::ostream & operator<<(std::ostream &str, const db_const_iterator &obj)
Definition: librpmDb.cc:706
void operator++()
Advance to next RpmHeader::constPtr.
Definition: librpmDb.cc:659
bool findByProvides(const std::string &tag_r)
Reset to iterate all packages that provide a certain tag.
Definition: librpmDb.cc:743
static std::string expand(const std::string &macro_r)
Definition: librpmDb.cc:142
static void dbAccess()
Access the database at the current default location.
Definition: librpmDb.cc:244
String related utilities and Regular expression matching.
bool findByRequiredBy(const std::string &tag_r)
Reset to iterate all packages that require a certain tag.
Definition: librpmDb.cc:754
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
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
virtual void unref_to(unsigned refCount_r) const
Trigger from Rep, after refCount was decreased.
Definition: librpmDb.cc:385
db_const_iterator(const db_const_iterator &)
Subclass to retrieve database content.
Definition: librpmDb.h:343
static librpmDb::constPtr _defaultDb
Current rpmdb handle.
Definition: librpmDb.h:82
intrusive_ptr< librpmDb > Ptr
Definition: librpmDb.h:40
static librpmDb * newLibrpmDb()
For internal use.
Definition: librpmDb.cc:162
virtual ~librpmDb()
Destructor.
Definition: librpmDb.cc:374
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
shared_ptr< RpmException > dbError() const
Return any database error.
Definition: librpmDb.cc:692
const std::string & asString() const
String representation.
Definition: Pathname.h:91
static Pathname _rpmDefaultDbPath
_dbpath configured in rpm config.
Definition: librpmDb.h:77
static Pathname _defaultRoot
Current root directory for all operations.
Definition: librpmDb.h:67
static const Pathname & defaultDbPath()
Definition: librpmDb.h:148
bool findByName(const std::string &name_r)
Reset to iterate all packages with a certain name.
Definition: librpmDb.cc:776
static unsigned dbRelease(bool force_r=false)
If there are no outstanding references to the database (e.g.
Definition: librpmDb.cc:277
shared_ptr< RpmException > error() const
Return any database error.
Definition: librpmDb.cc:421
bool findByFile(const std::string &file_r)
Reset to iterate all packages that own a certain file.
Definition: librpmDb.cc:732
Base class for reference counted objects.
const Pathname & root() const
Definition: librpmDb.cc:399
Manage access to librpm database.
Definition: librpmDb.h:37
bool findPackage(const std::string &name_r)
Find package by name.
Definition: librpmDb.cc:787
const RpmHeader::constPtr & operator->() const
Forwards to the current RpmHeader::constPtr.
Definition: librpmDb.h:402
static void unblockAccess()
Allow access to rpmdb e.g.
Definition: librpmDb.cc:327
static Pathname _defaultDbPath
Current directory (below root) that contains the rpmdb.
Definition: librpmDb.h:72
bool findAll()
Reset to iterate all packages.
Definition: librpmDb.cc:721
db_const_iterator & operator=(const db_const_iterator &)
librpmDb internal database handle
Definition: librpmDb.cc:39
const RpmHeader::constPtr & operator*() const
Returns the current RpmHeader::constPtr or NULL, if no more entries available.
Definition: librpmDb.cc:681
static bool globalInit()
Initialize lib librpm (read configfiles etc.).
Definition: librpmDb.cc:111
static unsigned blockAccess(const Pathname &root_r, const Pathname &dbPath_r)
Definition: librpmDb.h:216
bool findByConflicts(const std::string &tag_r)
Reset to iterate all packages that conflict with a certain tag.
Definition: librpmDb.cc:765
virtual std::ostream & dumpOn(std::ostream &str) const
Dump debug info.
Definition: librpmDb.cc:474
unsigned dbHdrNum() const
Returns the current headers index in database, 0 if no header.
Definition: librpmDb.cc:670
const Pathname & dbPath() const
Definition: librpmDb.cc:410
unsigned size() const
Definition: librpmDb.cc:443
intrusive_ptr< const librpmDb > constPtr
Definition: librpmDb.h:41
static bool isBlocked()
Definition: librpmDb.h:236
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
static Pathname suggestedDbPath(const Pathname &root_r)
Definition: librpmDb.cc:190
static std::ostream & dumpState(std::ostream &str)
Dump debug info.
Definition: librpmDb.cc:339
static std::string stringPath(const Pathname &root_r, const Pathname &sub_r)
Definition: librpmDb.h:130
TraitsType::constPtrType constPtr
Definition: Package.h:38