libzypp  13.10.6
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 
68  static Pathname _defaultRoot;
69 
74  static Pathname _defaultDbPath;
75 
80 
84  static bool _dbBlocked;
85 
93  static librpmDb * newLibrpmDb( Pathname root_r, Pathname dbPath_r, bool readonly_r );
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, const Pathname & dbPath_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 
231  class DbDirInfo;
232 
236  class db_const_iterator;
237 
238 private:
240  //
241  // internal database handle interface (nonstatic)
242  //
244 
248  class D;
249  D & _d;
250 
251 protected:
252 
257  librpmDb( const Pathname & root_r, const Pathname & dbPath_r, bool readonly_r );
258 
262  virtual void unref_to( unsigned refCount_r ) const;
263 
264 public:
265 
269  virtual ~librpmDb();
270 
274  const Pathname & root() const;
275 
279  const Pathname & dbPath() const;
280 
285  shared_ptr<RpmException> error() const;
286 
290  bool valid() const
291  {
292  return( ! error() );
293  }
294 
298  bool empty() const;
299 
303  unsigned size() const;
304 
305 public:
306 
310  void * dont_call_it() const;
311 
315  virtual std::ostream & dumpOn( std::ostream & str ) const;
316 };
317 
319 
321 //
322 // CLASS NAME : librpmDb::DbDirInfo
328 {
329  friend std::ostream & operator<<( std::ostream & str, const DbDirInfo & obj );
330 
331 private:
332 
336  Pathname _root;
337 
341  Pathname _dbPath;
342 
346  PathInfo _dbDir;
347 
351  PathInfo _dbV4;
352 
356  PathInfo _dbV3;
357 
361  PathInfo _dbV3ToV4;
362 
363 public:
364 
369  DbDirInfo( const Pathname & root_r, const Pathname & dbPath_r );
370 
371 public:
372 
376  const Pathname & root() const
377  {
378  return _root;
379  }
380 
384  const Pathname & dbPath() const
385  {
386  return _dbPath;
387  }
388 
392  const PathInfo & dbDir() const
393  {
394  return _dbDir;
395  }
396 
400  const PathInfo & dbV4() const
401  {
402  return _dbV4;
403  }
404 
408  const PathInfo & dbV3() const
409  {
410  return _dbV3;
411  }
412 
416  const PathInfo & dbV3ToV4() const
417  {
418  return _dbV3ToV4;
419  }
420 
421 public:
422 
426  void restat();
427 
428 public:
429 
433  bool illegalArgs() const
434  {
435  return _dbDir.path().empty();
436  }
437 
442  bool usableArgs() const
443  {
444  return _dbDir.isDir() || ! ( _dbDir.path().empty() || _dbDir.isExist() );
445  }
446 
450  bool hasDbDir() const
451  {
452  return _dbDir.isDir();
453  }
454 
458  bool hasDbV4() const
459  {
460  return _dbV4.isFile();
461  }
462 
466  bool hasDbV3() const
467  {
468  return _dbV3.isFile();
469  }
470 
474  bool hasDbV3ToV4() const
475  {
476  return _dbV3ToV4.isFile();
477  }
478 };
479 
481 
483 //
484 // CLASS NAME : librpmDb::db_const_iterator
491 {
492  db_const_iterator & operator=( const db_const_iterator & ); // NO ASSIGNMENT!
493  db_const_iterator ( const db_const_iterator & ); // NO COPY!
494  friend std::ostream & operator<<( std::ostream & str, const db_const_iterator & obj );
495  friend class librpmDb;
496 
497 private:
498 
502  class D;
503  D & _d;
504 
505 public:
506 
513  db_const_iterator( librpmDb::constPtr dbptr_r = 0 );
514 
519 
527  shared_ptr<RpmException> dbError() const;
528 
532  void operator++();
533 
538  unsigned dbHdrNum() const;
539 
544  const RpmHeader::constPtr & operator*() const;
545 
550  {
551  return operator*();
552  }
553 
554 public:
555 
564  bool findAll();
565 
569  bool findByFile( const std::string & file_r );
570 
574  bool findByProvides( const std::string & tag_r );
575 
579  bool findByRequiredBy( const std::string & tag_r );
580 
584  bool findByConflicts( const std::string & tag_r );
585 
596  bool findByName( const std::string & name_r );
597 
598 public:
599 
607  bool findPackage( const std::string & name_r );
608 
613  bool findPackage( const std::string & name_r, const Edition & ed_r );
614 
618  bool findPackage( const Package::constPtr & which_r );
619 };
620 
622 } //namespace rpm
623 } //namespace target
624 } // namespace zypp
625 
626 #endif // librpmDb_h
627 
PathInfo _dbV4
rpmV4 database (_dbDir/Packages)
Definition: librpmDb.h:351
bool hasDbV3ToV4() const
Whether dbV3ToV4 file exists.
Definition: librpmDb.h:474
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:65
static const Pathname & defaultRoot()
Definition: librpmDb.h:137
static bool _dbBlocked
Whether access is blocked (no _defaultDb will be available).
Definition: librpmDb.h:84
PathInfo _dbV3ToV4
rpmV3 database backup created on conversion to rpmV4 (_dbDir/packages.rpm3)
Definition: librpmDb.h:361
static unsigned blockAccess()
Blocks further access to rpmdb.
Definition: librpmDb.cc:326
static std::ostream & dumpState(std::ostream &str)
Dump debug info.
Definition: librpmDb.cc:351
friend std::ostream & operator<<(std::ostream &str, const db_const_iterator &obj)
void operator++()
Advance to next RpmHeader::constPtr.
Definition: librpmDb.cc:738
bool findByProvides(const std::string &tag_r)
Reset to iterate all packages that provide a certain tag.
Definition: librpmDb.cc:822
shared_ptr< RpmException > error() const
Return any database error.
Definition: librpmDb.cc:433
static std::string expand(const std::string &macro_r)
Definition: librpmDb.cc:159
Pathname _dbPath
Directory that contains the rpmdb.
Definition: librpmDb.h:341
Collect info about what kind of rpmdb seems to be present by looking at paths and filenames...
Definition: librpmDb.h:327
static void dbAccess()
Access the database at the current default location.
Definition: librpmDb.cc:248
bool findByRequiredBy(const std::string &tag_r)
Reset to iterate all packages that require a certain tag.
Definition: librpmDb.cc:833
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:374
virtual std::ostream & dumpOn(std::ostream &str) const
Dump debug info.
Definition: librpmDb.cc:486
static librpmDb * newLibrpmDb(Pathname root_r, Pathname dbPath_r, bool readonly_r)
For internal use.
Definition: librpmDb.cc:179
const Pathname & root() const
Root directory for all operations.
Definition: librpmDb.h:376
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
bool hasDbDir() const
Whether dbDir directory exists.
Definition: librpmDb.h:450
bool illegalArgs() const
Whether constructor arguments were illegal.
Definition: librpmDb.h:433
db_const_iterator(const db_const_iterator &)
DbDirInfo(const Pathname &root_r, const Pathname &dbPath_r)
For Constructor arguments see accessPath.
Definition: librpmDb.cc:504
const RpmHeader::constPtr & operator->() const
Forwards to the current RpmHeader::constPtr.
Definition: librpmDb.h:549
Subclass to retrieve database content.
Definition: librpmDb.h:490
bool hasDbV4() const
Whether dbV4 file exists.
Definition: librpmDb.h:458
static librpmDb::constPtr _defaultDb
Current rpmdb handle.
Definition: librpmDb.h:79
intrusive_ptr< librpmDb > Ptr
Definition: librpmDb.h:41
virtual ~librpmDb()
Destructor.
Definition: librpmDb.cc:386
const Pathname & root() const
Definition: librpmDb.cc:411
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
void * dont_call_it() const
Dont call it ;) It&#39;s for development and testing only.
Definition: librpmDb.cc:473
const PathInfo & dbV3ToV4() const
rpmV3 database backup created on conversion to rpmV4 (_dbDir/packages.rpm3)
Definition: librpmDb.h:416
shared_ptr< RpmException > dbError() const
Return any database error.
Definition: librpmDb.cc:771
static Pathname _defaultRoot
Current root directory for all operations.
Definition: librpmDb.h:68
static const Pathname & defaultDbPath()
Definition: librpmDb.h:145
bool findByName(const std::string &name_r)
Reset to iterate all packages with a certain name.
Definition: librpmDb.cc:855
PathInfo _dbDir
database directory (unset on illegal constructor arguments)
Definition: librpmDb.h:346
static unsigned dbRelease(bool force_r=false)
If there are no outstanding references to the database (e.g.
Definition: librpmDb.cc:289
bool hasDbV3() const
Whether dbV3 file exists.
Definition: librpmDb.h:466
const RpmHeader::constPtr & operator*() const
Returns the current RpmHeader::constPtr or NULL, if no more entries available.
Definition: librpmDb.cc:760
friend std::ostream & operator<<(std::ostream &str, const DbDirInfo &obj)
Definition: librpmDb.cc:544
bool findByFile(const std::string &file_r)
Reset to iterate all packages that own a certain file.
Definition: librpmDb.cc:811
Base class for reference counted objects.
Manage access to librpm database.
Definition: librpmDb.h:38
bool findPackage(const std::string &name_r)
Find package by name.
virtual void unref_to(unsigned refCount_r) const
Trigger from Rep, after refCount was decreased.
Definition: librpmDb.cc:397
static void unblockAccess()
Allow access to rpmdb e.g.
Definition: librpmDb.cc:339
const PathInfo & dbV4() const
rpmV4 database (_dbDir/Packages)
Definition: librpmDb.h:400
static Pathname _defaultDbPath
Current directory (below root) that contains the rpmdb.
Definition: librpmDb.h:74
unsigned size() const
Definition: librpmDb.cc:455
bool findAll()
Reset to iterate all packages.
Definition: librpmDb.cc:800
db_const_iterator & operator=(const db_const_iterator &)
librpmDb internal database handle
Definition: librpmDb.cc:36
static bool globalInit()
Initialize lib librpm (read configfiles etc.).
Definition: librpmDb.cc:128
bool findByConflicts(const std::string &tag_r)
Reset to iterate all packages that conflict with a certain tag.
Definition: librpmDb.cc:844
const PathInfo & dbDir() const
database directory (unset on illegal constructor arguments)
Definition: librpmDb.h:392
unsigned dbHdrNum() const
Returns the current headers index in database, 0 if no header.
Definition: librpmDb.cc:749
bool usableArgs() const
Whether constructor arguments were llegal and dbDir either is a directory or may be created (path doe...
Definition: librpmDb.h:442
const PathInfo & dbV3() const
rpmV3 database (_dbDir/packages.rpm)
Definition: librpmDb.h:408
intrusive_ptr< const librpmDb > constPtr
Definition: librpmDb.h:42
static bool isBlocked()
Definition: librpmDb.h:215
Pathname _root
Root directory for all operations.
Definition: librpmDb.h:336
PathInfo _dbV3
rpmV3 database (_dbDir/packages.rpm)
Definition: librpmDb.h:356
static std::string stringPath(const Pathname &root_r, const Pathname &sub_r)
Definition: librpmDb.h:127
const Pathname & dbPath() const
Directory that contains the rpmdb.
Definition: librpmDb.h:384
void restat()
Restat all paths.
Definition: librpmDb.cc:529
const Pathname & dbPath() const
Definition: librpmDb.cc:422
TraitsType::constPtrType constPtr
Definition: Package.h:38