libzypp  17.25.8
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 
18 #include <zypp/base/NonCopyable.h>
19 #include <zypp/base/PtrTypes.h>
20 #include <zypp/PathInfo.h>
21 #include <zypp/Package.h>
24 
25 namespace zypp
26 {
27 namespace target
28 {
29 namespace rpm
30 {
31 
33 //
34 // CLASS NAME : librpmDb
39 {
40 public:
41  typedef intrusive_ptr<librpmDb> Ptr;
42  typedef intrusive_ptr<const librpmDb> constPtr;
43 private:
53  static void dbAccess( librpmDb::Ptr & ptr_r );
54 
55 public:
56 
58  //
59  // static interface
60  //
62 private:
63 
69 
74 
79 
84 
88  static bool _dbBlocked;
89 
97  static librpmDb * newLibrpmDb();
98 
111  static void dbAccess();
112 
113 public:
114 
121  static bool globalInit();
122 
126  static std::string expand( const std::string & macro_r );
127 
131  static std::string stringPath( const Pathname & root_r, const Pathname & sub_r )
132  {
133  return std::string( "'(" ) + root_r.asString() + ")" + sub_r.asString() + "'";
134  }
135 
136 public:
137 
141  static const Pathname & defaultRoot()
142  {
143  return _defaultRoot;
144  }
145 
149  static const Pathname & defaultDbPath()
150  {
151  return _defaultDbPath;
152  }
153 
162  static Pathname suggestedDbPath( const Pathname & root_r );
163 
178  static void dbAccess( const Pathname & root_r );
179 
189  static void dbAccess( librpmDb::constPtr & ptr_r );
190 
203  static unsigned dbRelease( bool force_r = false );
204 
212  static unsigned blockAccess();
213 
224  static void unblockAccess();
225 
229  static bool isBlocked()
230  {
231  return _dbBlocked;
232  }
233 
237  static std::ostream & dumpState( std::ostream & str );
238 
239 public:
240 
244  class db_const_iterator;
245 
246 private:
248  //
249  // internal database handle interface (nonstatic)
250  //
252 
256  class D;
257  D & _d;
258 
259 protected:
260 
265  librpmDb( const Pathname & root_r, const Pathname & dbPath_r, bool readonly_r );
266 
270  virtual void unref_to( unsigned refCount_r ) const;
271 
272 public:
273 
277  virtual ~librpmDb();
278 
282  const Pathname & root() const;
283 
287  const Pathname & dbPath() const;
288 
293  shared_ptr<RpmException> error() const;
294 
298  bool valid() const
299  {
300  return( ! error() );
301  }
302 
306  bool empty() const;
307 
311  unsigned size() const;
312 
313 public:
314 
318  void * dont_call_it() const;
319 
323  virtual std::ostream & dumpOn( std::ostream & str ) const;
324 };
325 
327 
329 //
330 // CLASS NAME : librpmDb::db_const_iterator
337 {
338  db_const_iterator & operator=( const db_const_iterator & ); // NO ASSIGNMENT!
339  db_const_iterator ( const db_const_iterator & ); // NO COPY!
340  friend std::ostream & operator<<( std::ostream & str, const db_const_iterator & obj );
341  friend class librpmDb;
342 
343 private:
344 
348  class D;
349  D & _d;
350 
351 public:
352 
359  db_const_iterator( librpmDb::constPtr dbptr_r = 0 );
360 
365 
373  shared_ptr<RpmException> dbError() const;
374 
378  void operator++();
379 
384  unsigned dbHdrNum() const;
385 
390  const RpmHeader::constPtr & operator*() const;
391 
396  {
397  return operator*();
398  }
399 
400 public:
401 
410  bool findAll();
411 
415  bool findByFile( const std::string & file_r );
416 
420  bool findByProvides( const std::string & tag_r );
421 
425  bool findByRequiredBy( const std::string & tag_r );
426 
430  bool findByConflicts( const std::string & tag_r );
431 
442  bool findByName( const std::string & name_r );
443 
444 public:
445 
453  bool findPackage( const std::string & name_r );
454 
459  bool findPackage( const std::string & name_r, const Edition & ed_r );
460 
464  bool findPackage( const Package::constPtr & which_r );
465 };
466 
468 } //namespace rpm
469 } //namespace target
470 } // namespace zypp
471 
472 #endif // librpmDb_h
473 
zypp::target::rpm::librpmDb::dumpOn
virtual std::ostream & dumpOn(std::ostream &str) const
Dump debug info.
Definition: librpmDb.cc:474
zypp::target::rpm::librpmDb::db_const_iterator::operator=
db_const_iterator & operator=(const db_const_iterator &)
zypp::target::rpm::librpmDb::defaultDbPath
static const Pathname & defaultDbPath()
Definition: librpmDb.h:149
zypp::target::rpm::librpmDb::_dbBlocked
static bool _dbBlocked
Whether access is blocked (no _defaultDb will be available).
Definition: librpmDb.h:88
PathInfo.h
zypp::target::rpm::librpmDb::isBlocked
static bool isBlocked()
Definition: librpmDb.h:229
zypp::target::rpm::librpmDb::D
librpmDb internal database handle
Definition: librpmDb.cc:40
zypp::target::rpm::librpmDb::db_const_iterator::findByRequiredBy
bool findByRequiredBy(const std::string &tag_r)
Reset to iterate all packages that require a certain tag.
Definition: librpmDb.cc:754
zypp::target::rpm::librpmDb::valid
bool valid() const
Definition: librpmDb.h:298
RpmHeader.h
zypp::target::rpm::librpmDb::_defaultDb
static librpmDb::constPtr _defaultDb
Current rpmdb handle.
Definition: librpmDb.h:83
zypp::target::rpm::librpmDb::db_const_iterator::dbHdrNum
unsigned dbHdrNum() const
Returns the current headers index in database, 0 if no header.
Definition: librpmDb.cc:670
zypp::target::rpm::librpmDb::globalInit
static bool globalInit()
Initialize lib librpm (read configfiles etc.).
Definition: librpmDb.cc:111
zypp::target::rpm::RpmHeader::constPtr
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:64
zypp::Edition
Edition represents [epoch:]version[-release]
Definition: Edition.h:61
zypp::base::ReferenceCounted
Base class for reference counted objects.
Definition: ReferenceCounted.h:34
zypp::target::rpm::librpmDb::_defaultDbPath
static Pathname _defaultDbPath
Current directory (below root) that contains the rpmdb.
Definition: librpmDb.h:73
PtrTypes.h
zypp::Package::constPtr
TraitsType::constPtrType constPtr
Definition: Package.h:38
zypp::target::rpm::librpmDb::_rpmDefaultDbPath
static Pathname _rpmDefaultDbPath
_dbpath configured in rpm config.
Definition: librpmDb.h:78
zypp::target::rpm::librpmDb::db_const_iterator::operator++
void operator++()
Advance to next RpmHeader::constPtr.
Definition: librpmDb.cc:659
zypp::target::rpm::librpmDb::db_const_iterator::findByProvides
bool findByProvides(const std::string &tag_r)
Reset to iterate all packages that provide a certain tag.
Definition: librpmDb.cc:743
RpmException.h
zypp::target::rpm::librpmDb::~librpmDb
virtual ~librpmDb()
Destructor.
Definition: librpmDb.cc:374
zypp::target::rpm::librpmDb::blockAccess
static unsigned blockAccess()
Blocks further access to rpmdb.
Definition: librpmDb.cc:314
zypp::target::rpm::librpmDb::unblockAccess
static void unblockAccess()
Allow access to rpmdb e.g.
Definition: librpmDb.cc:327
zypp::target::rpm::librpmDb::error
shared_ptr< RpmException > error() const
Return any database error.
Definition: librpmDb.cc:421
Package.h
zypp::base::NonCopyable
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
zypp::target::rpm::librpmDb::empty
bool empty() const
Definition: librpmDb.cc:432
zypp::target::rpm::librpmDb::_d
D & _d
Definition: librpmDb.h:256
zypp::target::rpm::librpmDb::dbAccess
static void dbAccess()
Access the database at the current default location.
Definition: librpmDb.cc:244
zypp::target::rpm::librpmDb::size
unsigned size() const
Definition: librpmDb.cc:443
zypp::target::rpm::librpmDb::stringPath
static std::string stringPath(const Pathname &root_r, const Pathname &sub_r)
Definition: librpmDb.h:131
zypp::target::rpm::librpmDb::db_const_iterator::D
Definition: librpmDb.cc:487
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::target::rpm::librpmDb::dont_call_it
void * dont_call_it() const
Dont call it ;) It's for development and testing only.
Definition: librpmDb.cc:461
zypp::target::rpm::librpmDb::db_const_iterator::findAll
bool findAll()
Reset to iterate all packages.
Definition: librpmDb.cc:721
zypp::target::rpm::librpmDb::db_const_iterator::findByConflicts
bool findByConflicts(const std::string &tag_r)
Reset to iterate all packages that conflict with a certain tag.
Definition: librpmDb.cc:765
zypp::target::rpm::librpmDb::unref_to
virtual void unref_to(unsigned refCount_r) const
Trigger from Rep, after refCount was decreased.
Definition: librpmDb.cc:385
zypp::target::rpm::librpmDb::librpmDb
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
zypp::target::rpm::librpmDb::db_const_iterator
Subclass to retrieve database content.
Definition: librpmDb.h:337
zypp::target::rpm::librpmDb::db_const_iterator::findByName
bool findByName(const std::string &name_r)
Reset to iterate all packages with a certain name.
Definition: librpmDb.cc:776
zypp::target::rpm::librpmDb::db_const_iterator::findPackage
bool findPackage(const std::string &name_r)
Find package by name.
Definition: librpmDb.cc:787
ReferenceCounted.h
zypp::target::rpm::librpmDb::suggestedDbPath
static Pathname suggestedDbPath(const Pathname &root_r)
Definition: librpmDb.cc:190
zypp::target::rpm::librpmDb::db_const_iterator::~db_const_iterator
~db_const_iterator()
Destructor.
Definition: librpmDb.cc:648
zypp::target::rpm::librpmDb::db_const_iterator::operator*
const RpmHeader::constPtr & operator*() const
Returns the current RpmHeader::constPtr or NULL, if no more entries available.
Definition: librpmDb.cc:681
zypp::target::rpm::librpmDb::_defaultRoot
static Pathname _defaultRoot
Current root directory for all operations.
Definition: librpmDb.h:68
zypp::target::rpm::librpmDb::constPtr
intrusive_ptr< const librpmDb > constPtr
Definition: librpmDb.h:42
zypp::target::rpm::librpmDb::db_const_iterator::db_const_iterator
db_const_iterator(const db_const_iterator &)
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:45
zypp::target::rpm::librpmDb::db_const_iterator::operator->
const RpmHeader::constPtr & operator->() const
Forwards to the current RpmHeader::constPtr.
Definition: librpmDb.h:395
zypp::target::rpm::librpmDb::dumpState
static std::ostream & dumpState(std::ostream &str)
Dump debug info.
Definition: librpmDb.cc:339
zypp::target::rpm::librpmDb::dbRelease
static unsigned dbRelease(bool force_r=false)
If there are no outstanding references to the database (e.g.
Definition: librpmDb.cc:277
zypp::target::rpm::librpmDb::dbPath
const Pathname & dbPath() const
Definition: librpmDb.cc:410
zypp::target::rpm::librpmDb::db_const_iterator::dbError
shared_ptr< RpmException > dbError() const
Return any database error.
Definition: librpmDb.cc:692
zypp::target::rpm::librpmDb::dbAccess
static void dbAccess(librpmDb::Ptr &ptr_r)
INTENTIONALLY UNDEFINED<\B> because of bug in Ptr classes which allows implicit conversion from librp...
zypp::target::rpm::librpmDb::db_const_iterator::findByFile
bool findByFile(const std::string &file_r)
Reset to iterate all packages that own a certain file.
Definition: librpmDb.cc:732
zypp::target::rpm::librpmDb
Manage access to librpm database.
Definition: librpmDb.h:39
zypp::target::rpm::librpmDb::expand
static std::string expand(const std::string &macro_r)
Definition: librpmDb.cc:142
str
String related utilities and Regular expression matching.
zypp::target::rpm::librpmDb::defaultRoot
static const Pathname & defaultRoot()
Definition: librpmDb.h:141
zypp::filesystem::Pathname::asString
const std::string & asString() const
String representation.
Definition: Pathname.h:91
zypp::target::rpm::librpmDb::db_const_iterator::operator<<
friend std::ostream & operator<<(std::ostream &str, const db_const_iterator &obj)
Definition: librpmDb.cc:706
zypp::target::rpm::librpmDb::root
const Pathname & root() const
Definition: librpmDb.cc:399
zypp::target::rpm::librpmDb::Ptr
intrusive_ptr< librpmDb > Ptr
Definition: librpmDb.h:41
zypp::target::rpm::librpmDb::newLibrpmDb
static librpmDb * newLibrpmDb()
For internal use.
Definition: librpmDb.cc:162
NonCopyable.h
zypp::target::rpm::librpmDb::db_const_iterator::_d
D & _d
Definition: librpmDb.h:348