libzypp  17.25.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 
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  static const Pathname _defaultDbPath;
75 
80 
84  static bool _dbBlocked;
85 
93  static librpmDb * newLibrpmDb();
94 
107  static void dbAccess();
108 
109 public:
110 
117  static bool globalInit();
118 
122  static std::string expand( const std::string & macro_r );
123 
127  static std::string stringPath( const Pathname & root_r, const Pathname & sub_r )
128  {
129  return std::string( "'(" ) + root_r.asString() + ")" + sub_r.asString() + "'";
130  }
131 
132 public:
133 
137  static const Pathname & defaultRoot()
138  {
139  return _defaultRoot;
140  }
141 
145  static const Pathname & defaultDbPath()
146  {
147  return _defaultDbPath;
148  }
149 
164  static void dbAccess( const Pathname & root_r );
165 
175  static void dbAccess( librpmDb::constPtr & ptr_r );
176 
189  static unsigned dbRelease( bool force_r = false );
190 
198  static unsigned blockAccess();
199 
210  static void unblockAccess();
211 
215  static bool isBlocked()
216  {
217  return _dbBlocked;
218  }
219 
223  static std::ostream & dumpState( std::ostream & str );
224 
225 public:
226 
230  class db_const_iterator;
231 
232 private:
234  //
235  // internal database handle interface (nonstatic)
236  //
238 
242  class D;
243  D & _d;
244 
245 protected:
246 
251  librpmDb( const Pathname & root_r, const Pathname & dbPath_r, bool readonly_r );
252 
256  virtual void unref_to( unsigned refCount_r ) const;
257 
258 public:
259 
263  virtual ~librpmDb();
264 
268  const Pathname & root() const;
269 
273  const Pathname & dbPath() const;
274 
279  shared_ptr<RpmException> error() const;
280 
284  bool valid() const
285  {
286  return( ! error() );
287  }
288 
292  bool empty() const;
293 
297  unsigned size() const;
298 
299 public:
300 
304  void * dont_call_it() const;
305 
309  virtual std::ostream & dumpOn( std::ostream & str ) const;
310 };
311 
313 
315 //
316 // CLASS NAME : librpmDb::db_const_iterator
323 {
324  db_const_iterator & operator=( const db_const_iterator & ); // NO ASSIGNMENT!
325  db_const_iterator ( const db_const_iterator & ); // NO COPY!
326  friend std::ostream & operator<<( std::ostream & str, const db_const_iterator & obj );
327  friend class librpmDb;
328 
329 private:
330 
334  class D;
335  D & _d;
336 
337 public:
338 
345  db_const_iterator( librpmDb::constPtr dbptr_r = 0 );
346 
351 
359  shared_ptr<RpmException> dbError() const;
360 
364  void operator++();
365 
370  unsigned dbHdrNum() const;
371 
376  const RpmHeader::constPtr & operator*() const;
377 
382  {
383  return operator*();
384  }
385 
386 public:
387 
396  bool findAll();
397 
401  bool findByFile( const std::string & file_r );
402 
406  bool findByProvides( const std::string & tag_r );
407 
411  bool findByRequiredBy( const std::string & tag_r );
412 
416  bool findByConflicts( const std::string & tag_r );
417 
428  bool findByName( const std::string & name_r );
429 
430 public:
431 
439  bool findPackage( const std::string & name_r );
440 
445  bool findPackage( const std::string & name_r, const Edition & ed_r );
446 
450  bool findPackage( const Package::constPtr & which_r );
451 };
452 
454 } //namespace rpm
455 } //namespace target
456 } // namespace zypp
457 
458 #endif // librpmDb_h
459 
zypp::target::rpm::librpmDb::dumpOn
virtual std::ostream & dumpOn(std::ostream &str) const
Dump debug info.
Definition: librpmDb.cc:461
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:145
zypp::target::rpm::librpmDb::_dbBlocked
static bool _dbBlocked
Whether access is blocked (no _defaultDb will be available).
Definition: librpmDb.h:84
PathInfo.h
zypp::target::rpm::librpmDb::isBlocked
static bool isBlocked()
Definition: librpmDb.h:215
zypp::target::rpm::librpmDb::D
librpmDb internal database handle
Definition: librpmDb.cc:39
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:742
zypp::target::rpm::librpmDb::valid
bool valid() const
Definition: librpmDb.h:284
RpmHeader.h
zypp::target::rpm::librpmDb::_defaultDb
static librpmDb::constPtr _defaultDb
Current rpmdb handle.
Definition: librpmDb.h:79
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:659
zypp::target::rpm::librpmDb::globalInit
static bool globalInit()
Initialize lib librpm (read configfiles etc.).
Definition: librpmDb.cc:115
zypp::target::rpm::RpmHeader::constPtr
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:64
zypp::Edition
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
zypp::base::ReferenceCounted
Base class for reference counted objects.
Definition: ReferenceCounted.h:33
PtrTypes.h
zypp::Package::constPtr
TraitsType::constPtrType constPtr
Definition: Package.h:38
zypp::target::rpm::librpmDb::db_const_iterator::operator++
void operator++()
Advance to next RpmHeader::constPtr.
Definition: librpmDb.cc:648
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:731
RpmException.h
zypp::target::rpm::librpmDb::~librpmDb
virtual ~librpmDb()
Destructor.
Definition: librpmDb.cc:361
zypp::target::rpm::librpmDb::blockAccess
static unsigned blockAccess()
Blocks further access to rpmdb.
Definition: librpmDb.cc:301
zypp::target::rpm::librpmDb::unblockAccess
static void unblockAccess()
Allow access to rpmdb e.g.
Definition: librpmDb.cc:314
zypp::target::rpm::librpmDb::error
shared_ptr< RpmException > error() const
Return any database error.
Definition: librpmDb.cc:408
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:419
zypp::target::rpm::librpmDb::_d
D & _d
Definition: librpmDb.h:242
zypp::target::rpm::librpmDb::dbAccess
static void dbAccess()
Access the database at the current default location.
Definition: librpmDb.cc:231
zypp::target::rpm::librpmDb::size
unsigned size() const
Definition: librpmDb.cc:430
zypp::target::rpm::librpmDb::stringPath
static std::string stringPath(const Pathname &root_r, const Pathname &sub_r)
Definition: librpmDb.h:127
zypp::target::rpm::librpmDb::db_const_iterator::D
Definition: librpmDb.cc:473
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
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:448
zypp::target::rpm::librpmDb::db_const_iterator::findAll
bool findAll()
Reset to iterate all packages.
Definition: librpmDb.cc:709
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:753
zypp::target::rpm::librpmDb::unref_to
virtual void unref_to(unsigned refCount_r) const
Trigger from Rep, after refCount was decreased.
Definition: librpmDb.cc:372
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:349
zypp::target::rpm::librpmDb::db_const_iterator
Subclass to retrieve database content.
Definition: librpmDb.h:322
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:764
zypp::target::rpm::librpmDb::_defaultDbPath
static const Pathname _defaultDbPath
Current directory (below root) that contains the rpmdb.
Definition: librpmDb.h:74
zypp::target::rpm::librpmDb::db_const_iterator::findPackage
bool findPackage(const std::string &name_r)
Find package by name.
Definition: librpmDb.cc:775
ReferenceCounted.h
zypp::target::rpm::librpmDb::db_const_iterator::~db_const_iterator
~db_const_iterator()
Destructor.
Definition: librpmDb.cc:637
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:670
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:44
zypp::target::rpm::librpmDb::db_const_iterator::operator->
const RpmHeader::constPtr & operator->() const
Forwards to the current RpmHeader::constPtr.
Definition: librpmDb.h:381
zypp::target::rpm::librpmDb::dumpState
static std::ostream & dumpState(std::ostream &str)
Dump debug info.
Definition: librpmDb.cc:326
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:264
zypp::target::rpm::librpmDb::dbPath
const Pathname & dbPath() const
Definition: librpmDb.cc:397
zypp::target::rpm::librpmDb::db_const_iterator::dbError
shared_ptr< RpmException > dbError() const
Return any database error.
Definition: librpmDb.cc:681
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:720
zypp::target::rpm::librpmDb
Manage access to librpm database.
Definition: librpmDb.h:38
zypp::target::rpm::librpmDb::expand
static std::string expand(const std::string &macro_r)
Definition: librpmDb.cc:146
str
String related utilities and Regular expression matching.
zypp::target::rpm::librpmDb::defaultRoot
static const Pathname & defaultRoot()
Definition: librpmDb.h:137
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:694
zypp::target::rpm::librpmDb::root
const Pathname & root() const
Definition: librpmDb.cc:386
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:166
NonCopyable.h
zypp::target::rpm::librpmDb::db_const_iterator::_d
D & _d
Definition: librpmDb.h:334