00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef librpmDb_h
00022 #define librpmDb_h
00023
00024 #include <iosfwd>
00025
00026 #include <y2util/PathInfo.h>
00027 #include <y2util/ProgressCounter.h>
00028
00029 #include <y2pm/InstTargetError.h>
00030 #include <y2pm/librpmDbPtr.h>
00031 #include <y2pm/RpmHeader.h>
00032
00034
00035
00039 class librpmDb : public CountedRep {
00040 REP_BODY(librpmDb);
00047 static PMError dbAccess( librpmDbPtr & ptr_r );
00048
00049 public:
00050
00054 typedef InstTargetError Error;
00055
00057
00058
00059
00061 private:
00062
00067 static Pathname _defaultRoot;
00068
00073 static Pathname _defaultDbPath;
00074
00078 static constlibrpmDbPtr _defaultDb;
00079
00083 static bool _dbBlocked;
00084
00089 static librpmDb * newLibrpmDb( Pathname root_r, Pathname dbPath_r, bool readonly_r, PMError & err_r );
00090
00102 static PMError dbAccess();
00103
00104 public:
00105
00112 static bool globalInit();
00113
00117 static std::string expand( const std::string & macro_r );
00118
00122 static std::string stringPath( const Pathname & root_r, const Pathname & sub_r ) {
00123 return std::string( "'(" ) + root_r.asString() + ")" + sub_r.asString() + "'";
00124 }
00125
00126 public:
00127
00131 static const Pathname & defaultRoot() { return _defaultRoot; }
00132
00136 static const Pathname & defaultDbPath() { return _defaultDbPath; }
00137
00151 static PMError dbAccess( const Pathname & root_r, const Pathname & dbPath_r );
00152
00161 static PMError dbAccess( constlibrpmDbPtr & ptr_r );
00162
00175 static unsigned dbRelease( bool force_r = false );
00176
00184 static unsigned blockAccess();
00185
00196 static void unblockAccess();
00197
00201 static bool isBlocked() { return _dbBlocked; }
00202
00206 static std::ostream & dumpState( std::ostream & str );
00207
00208 public:
00209
00214 class DbDirInfo;
00215
00219 class db_const_iterator;
00220
00221 private:
00223
00224
00225
00227
00231 class D;
00232 D & _d;
00233
00234 protected:
00235
00240 librpmDb( const Pathname & root_r, const Pathname & dbPath_r, bool readonly_r );
00241
00245 virtual void unref_to( unsigned refCount_r ) const;
00246
00247 public:
00248
00252 virtual ~librpmDb();
00253
00257 const Pathname & root() const;
00258
00262 const Pathname & dbPath() const;
00263
00268 PMError error() const;
00269
00273 bool valid() const { return( ! error() ); }
00274
00278 bool empty() const;
00279
00280 public:
00281
00285 void * dont_call_it() const;
00286
00290 virtual std::ostream & dumpOn( std::ostream & str ) const;
00291 };
00292
00294
00296
00297
00302 class librpmDb::DbDirInfo {
00303 friend std::ostream & operator<<( std::ostream & str, const DbDirInfo & obj );
00304
00305 private:
00306
00310 Pathname _root;
00311
00315 Pathname _dbPath;
00316
00320 PathInfo _dbDir;
00321
00325 PathInfo _dbV4;
00326
00330 PathInfo _dbV3;
00331
00335 PathInfo _dbV3ToV4;
00336
00337 public:
00338
00343 DbDirInfo( const Pathname & root_r, const Pathname & dbPath_r );
00344
00345 public:
00346
00350 const Pathname & root() const { return _root; }
00351
00355 const Pathname & dbPath() const { return _dbPath; }
00356
00360 const PathInfo & dbDir() const { return _dbDir; }
00361
00365 const PathInfo & dbV4() const { return _dbV4; }
00366
00370 const PathInfo & dbV3() const { return _dbV3; }
00371
00375 const PathInfo & dbV3ToV4() const { return _dbV3ToV4; }
00376
00377 public:
00378
00382 void restat();
00383
00384 public:
00385
00389 bool illegalArgs() const { return _dbDir.path().empty(); }
00390
00395 bool usableArgs() const { return _dbDir.isDir() || ! ( _dbDir.path().empty() || _dbDir.isExist() ); }
00396
00400 bool hasDbDir() const { return _dbDir.isDir(); }
00401
00405 bool hasDbV4() const { return _dbV4.isFile(); }
00406
00410 bool hasDbV3() const { return _dbV3.isFile(); }
00411
00415 bool hasDbV3ToV4() const { return _dbV3ToV4.isFile(); }
00416 };
00417
00419
00421
00422
00428 class librpmDb::db_const_iterator {
00429 db_const_iterator & operator=( const db_const_iterator & );
00430 db_const_iterator ( const db_const_iterator & );
00431 friend std::ostream & operator<<( std::ostream & str, const db_const_iterator & obj );
00432 friend class librpmDb;
00433
00434 private:
00435
00439 class D;
00440 D & _d;
00441
00442 public:
00443
00450 db_const_iterator( constlibrpmDbPtr dbptr_r = 0 );
00451
00455 ~db_const_iterator();
00456
00464 PMError dbError() const;
00465
00469 void operator++();
00470
00475 unsigned dbHdrNum() const;
00476
00481 const constRpmHeaderPtr & operator*() const;
00482
00486 const constRpmHeaderPtr & operator->() const {
00487 return operator*();
00488 }
00489
00490 public:
00491
00500 bool findAll();
00501
00505 bool findByFile( const std::string & file_r );
00506
00510 bool findByProvides( const std::string & tag_r );
00511
00515 bool findByRequiredBy( const std::string & tag_r );
00516
00520 bool findByConflicts( const std::string & tag_r );
00521
00532 bool findByName( const PkgName & name_r );
00533
00534 public:
00535
00543 bool findPackage( const PkgName & name_r );
00544
00549 bool findPackage( const PkgName & name_r, const PkgEdition & ed_r );
00553 bool findPackage( const PkgNameEd & which_r ) {
00554 return findPackage( which_r.name, which_r.edition );
00555 }
00559 bool findPackage( const constPMPackagePtr & which_r );
00560 };
00561
00563
00564 #endif // librpmDb_h
00565