libzypp 17.25.7
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
19#include <zypp/base/PtrTypes.h>
20#include <zypp/PathInfo.h>
21#include <zypp/Package.h>
24
25namespace zypp
26{
27namespace target
28{
29namespace rpm
30{
31
33//
34// CLASS NAME : librpmDb
39{
40public:
41 typedef intrusive_ptr<librpmDb> Ptr;
42 typedef intrusive_ptr<const librpmDb> constPtr;
43private:
53 static void dbAccess( librpmDb::Ptr & ptr_r );
54
55public:
56
58 //
59 // static interface
60 //
62private:
63
69
74
79
84
88 static bool _dbBlocked;
89
97 static librpmDb * newLibrpmDb();
98
111 static void dbAccess();
112
113public:
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
136public:
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
239public:
240
244 class db_const_iterator;
245
246private:
248 //
249 // internal database handle interface (nonstatic)
250 //
252
256 class D;
257 D & _d;
258
259protected:
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
272public:
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
313public:
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
343private:
344
348 class D;
349 D & _d;
350
351public:
352
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
400public:
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
444public:
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
Edition represents [epoch:]version[-release]
Definition: Edition.h:61
TraitsType::constPtrType constPtr
Definition: Package.h:38
Base class for reference counted objects.
const std::string & asString() const
String representation.
Definition: Pathname.h:91
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:64
librpmDb internal database handle
Definition: librpmDb.cc:40
Subclass to retrieve database content.
Definition: librpmDb.h:337
unsigned dbHdrNum() const
Returns the current headers index in database, 0 if no header.
Definition: librpmDb.cc:670
bool findByProvides(const std::string &tag_r)
Reset to iterate all packages that provide a certain tag.
Definition: librpmDb.cc:743
bool findByName(const std::string &name_r)
Reset to iterate all packages with a certain name.
Definition: librpmDb.cc:776
db_const_iterator & operator=(const db_const_iterator &)
const RpmHeader::constPtr & operator->() const
Forwards to the current RpmHeader::constPtr.
Definition: librpmDb.h:395
bool findByFile(const std::string &file_r)
Reset to iterate all packages that own a certain file.
Definition: librpmDb.cc:732
bool findAll()
Reset to iterate all packages.
Definition: librpmDb.cc:721
const RpmHeader::constPtr & operator*() const
Returns the current RpmHeader::constPtr or NULL, if no more entries available.
Definition: librpmDb.cc:681
friend std::ostream & operator<<(std::ostream &str, const db_const_iterator &obj)
Definition: librpmDb.cc:706
bool findByRequiredBy(const std::string &tag_r)
Reset to iterate all packages that require a certain tag.
Definition: librpmDb.cc:754
bool findPackage(const std::string &name_r)
Find package by name.
Definition: librpmDb.cc:787
shared_ptr< RpmException > dbError() const
Return any database error.
Definition: librpmDb.cc:692
void operator++()
Advance to next RpmHeader::constPtr.
Definition: librpmDb.cc:659
bool findByConflicts(const std::string &tag_r)
Reset to iterate all packages that conflict with a certain tag.
Definition: librpmDb.cc:765
db_const_iterator(const db_const_iterator &)
Manage access to librpm database.
Definition: librpmDb.h:39
static bool _dbBlocked
Whether access is blocked (no _defaultDb will be available).
Definition: librpmDb.h:88
virtual void unref_to(unsigned refCount_r) const
Trigger from Rep, after refCount was decreased.
Definition: librpmDb.cc:385
static const Pathname & defaultDbPath()
Definition: librpmDb.h:149
const Pathname & dbPath() const
Definition: librpmDb.cc:410
const Pathname & root() const
Definition: librpmDb.cc:399
static bool globalInit()
Initialize lib librpm (read configfiles etc.).
Definition: librpmDb.cc:111
virtual std::ostream & dumpOn(std::ostream &str) const
Dump debug info.
Definition: librpmDb.cc:474
static const Pathname & defaultRoot()
Definition: librpmDb.h:141
intrusive_ptr< const librpmDb > constPtr
Definition: librpmDb.h:42
intrusive_ptr< librpmDb > Ptr
Definition: librpmDb.h:41
unsigned size() const
Definition: librpmDb.cc:443
static std::string stringPath(const Pathname &root_r, const Pathname &sub_r)
Definition: librpmDb.h:131
static unsigned dbRelease(bool force_r=false)
If there are no outstanding references to the database (e.g.
Definition: librpmDb.cc:277
static std::ostream & dumpState(std::ostream &str)
Dump debug info.
Definition: librpmDb.cc:339
static librpmDb::constPtr _defaultDb
Current rpmdb handle.
Definition: librpmDb.h:83
shared_ptr< RpmException > error() const
Return any database error.
Definition: librpmDb.cc:421
static bool isBlocked()
Definition: librpmDb.h:229
static Pathname _rpmDefaultDbPath
_dbpath configured in rpm config.
Definition: librpmDb.h:78
static Pathname _defaultDbPath
Current directory (below root) that contains the rpmdb.
Definition: librpmDb.h:73
static librpmDb * newLibrpmDb()
For internal use.
Definition: librpmDb.cc:162
virtual ~librpmDb()
Destructor.
Definition: librpmDb.cc:374
void * dont_call_it() const
Dont call it ;) It's for development and testing only.
Definition: librpmDb.cc:461
static Pathname _defaultRoot
Current root directory for all operations.
Definition: librpmDb.h:68
static std::string expand(const std::string &macro_r)
Definition: librpmDb.cc:142
static void dbAccess(librpmDb::Ptr &ptr_r)
INTENTIONALLY UNDEFINED<\B> because of bug in Ptr classes which allows implicit conversion from librp...
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
static void dbAccess()
Access the database at the current default location.
Definition: librpmDb.cc:244
static unsigned blockAccess()
Blocks further access to rpmdb.
Definition: librpmDb.cc:314
static Pathname suggestedDbPath(const Pathname &root_r)
Definition: librpmDb.cc:190
static void unblockAccess()
Allow access to rpmdb e.g.
Definition: librpmDb.cc:327
String related utilities and Regular expression matching.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2