libzypp  11.13.5
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