libzypp  17.35.15
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>
23 
24 namespace zypp
25 {
26 namespace target
27 {
28 namespace rpm
29 {
30  struct _dumpPath {
31  _dumpPath( const Pathname & root_r, const Pathname & sub_r )
32  : _root {root_r }
33  , _sub { sub_r }
34  {}
35  const Pathname & _root;
36  const Pathname & _sub;
37  };
38  inline std::ostream & operator<<( std::ostream & str, const _dumpPath & obj )
39  { return str << "'(" << obj._root << ")" << obj._sub << "'"; }
40 
42  inline _dumpPath dumpPath( const Pathname & root_r, const Pathname & sub_r )
43  { return _dumpPath( root_r, sub_r ); }
44 
46 //
47 // CLASS NAME : librpmDb
52 {
53 public:
54  using Ptr = intrusive_ptr<librpmDb>;
55  using constPtr = intrusive_ptr<const librpmDb>;
56 
57 private:
65  static void dbAccess( librpmDb::Ptr & ptr_r );
66 
67 public:
69  //
70  // static interface
71  //
73 
80  static bool globalInit();
81 
85  static std::string expand( const std::string & macro_r );
86 
94  static Pathname suggestedDbPath( const Pathname & root_r );
95 
103  static bool dbExists( const Pathname & root_r, const Pathname & dbPath_r = Pathname() );
104 
112  static librpmDb::constPtr dbOpenIf( const Pathname & root_r, const Pathname & dbPath_r = Pathname() );
113 
121  static librpmDb::constPtr dbOpenCreate( const Pathname & root_r, const Pathname & dbPath_r = Pathname() );
122 
126  class db_const_iterator;
127 
128 private:
129 
134  static librpmDb::constPtr dbAccess( const Pathname & root_r, const Pathname & dbPath_r, bool create_r = false );
135 
136 private:
138  //
139  // internal database handle interface (nonstatic)
140  //
142 
146  class D;
147  D & _d;
148 
153  librpmDb( const Pathname & root_r, const Pathname & dbPath_r, bool readonly_r = true );
154 
158  void unref_to( unsigned refCount_r ) const override;
159 
160 public:
161 
165  ~librpmDb() override;
166 
170  const Pathname & root() const;
171 
175  const Pathname & dbPath() const;
176 
177 public:
178 
182  std::ostream & dumpOn( std::ostream & str ) const override;
183 };
184 
198 {
199  db_const_iterator & operator=( const db_const_iterator & ); // NO ASSIGNMENT!
200  db_const_iterator ( const db_const_iterator & ); // NO COPY!
201  friend std::ostream & operator<<( std::ostream & str, const db_const_iterator & obj );
202  friend class librpmDb;
203 
204 private:
205 
209  class D;
210  D & _d;
211 
212 #if LEGACY(1735)
213 public:
222 #endif
223 
224 public:
230 
232  explicit db_const_iterator( const Pathname & root_r );
233 
235  db_const_iterator( const Pathname & root_r, const Pathname & dbPath_r );
236 
240  db_const_iterator( std::nullptr_t );
241 
246 
248  bool hasDB() const;
249 
253  void operator++();
254 
259  unsigned dbHdrNum() const;
260 
265  const RpmHeader::constPtr & operator*() const;
266 
270  const RpmHeader::constPtr & operator->() const
271  {
272  return operator*();
273  }
274 
275 public:
276 
281  bool findAll();
282 
286  bool findByFile( const std::string & file_r );
287 
291  bool findByProvides( const std::string & tag_r );
292 
296  bool findByRequiredBy( const std::string & tag_r );
297 
301  bool findByConflicts( const std::string & tag_r );
302 
313  bool findByName( const std::string & name_r );
314 
315 public:
316 
324  bool findPackage( const std::string & name_r );
325 
330  bool findPackage( const std::string & name_r, const Edition & ed_r );
331 
335  bool findPackage( const Package::constPtr & which_r );
336 };
337 
339 std::ostream & operator<<( std::ostream & str, const librpmDb::db_const_iterator & obj ) ZYPP_API;
340 
342 } //namespace rpm
343 } //namespace target
344 } // namespace zypp
345 
346 #endif // librpmDb_h
347 
TraitsType::constPtrType constPtr
Definition: Package.h:39
static std::string expand(const std::string &macro_r)
Definition: librpmDb.cc:159
std::ostream & operator<<(std::ostream &str, const librpmDb::db_const_iterator &obj)
Definition: librpmDb.cc:412
String related utilities and Regular expression matching.
static bool dbExists(const Pathname &root_r, const Pathname &dbPath_r=Pathname())
Definition: librpmDb.cc:183
Definition: Arch.h:363
static librpmDb::constPtr dbOpenCreate(const Pathname &root_r, const Pathname &dbPath_r=Pathname())
Assert the rpmdb below the system at root_r exists.
Definition: librpmDb.cc:198
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
~librpmDb() override
Destructor.
Definition: librpmDb.cc:231
std::ostream & dumpOn(std::ostream &str) const override
Dump debug info.
Definition: librpmDb.cc:246
_dumpPath dumpPath(const Pathname &root_r, const Pathname &sub_r)
dumpPath iomaip to dump &#39;(root_r)sub_r&#39; output,
Definition: librpmDb.h:42
Subclass to retrieve rpm database content.
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition: ResTraits.h:93
const Pathname & _sub
Definition: librpmDb.h:36
intrusive_ptr< librpmDb > Ptr
Definition: librpmDb.h:54
Base class for reference counted objects.
const Pathname & root() const
Definition: librpmDb.cc:240
static librpmDb::constPtr dbOpenIf(const Pathname &root_r, const Pathname &dbPath_r=Pathname())
Open the rpmdb below the system at root_r (if it exists).
Definition: librpmDb.cc:195
void unref_to(unsigned refCount_r) const override
Trigger from Rep, after refCount was decreased.
Definition: librpmDb.cc:237
librpmDb internal database handle
Definition: librpmDb.cc:92
const Pathname & _root
Definition: librpmDb.h:35
static bool globalInit()
Initialize lib librpm (read configfiles etc.).
Definition: librpmDb.cc:139
static void dbAccess(librpmDb::Ptr &ptr_r)
INTENTIONALLY UNDEFINED<> because of bug in Ptr classes which allows implicit conversion from librpmD...
const Pathname & dbPath() const
Definition: librpmDb.cc:243
Wrapper class for rpm header struct.
Definition: RpmHeader.h:61
intrusive_ptr< const librpmDb > constPtr
Definition: librpmDb.h:55
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
static Pathname suggestedDbPath(const Pathname &root_r)
Definition: librpmDb.cc:171
#define ZYPP_DEPRECATED
The ZYPP_DEPRECATED macro can be used to trigger compile-time warnings with gcc >= 3...
Definition: Globals.h:116
_dumpPath(const Pathname &root_r, const Pathname &sub_r)
Definition: librpmDb.h:31
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26