libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #ifndef librpmDb_h 00013 #define librpmDb_h 00014 00015 #include <iosfwd> 00016 00017 #include "zypp/base/ReferenceCounted.h" 00018 #include "zypp/base/NonCopyable.h" 00019 #include "zypp/base/PtrTypes.h" 00020 #include "zypp/PathInfo.h" 00021 #include "zypp/Package.h" 00022 #include "zypp/target/rpm/RpmHeader.h" 00023 #include "zypp/target/rpm/RpmException.h" 00024 00025 namespace zypp 00026 { 00027 namespace target 00028 { 00029 namespace rpm 00030 { 00031 00033 // 00034 // CLASS NAME : librpmDb 00038 class librpmDb : public base::ReferenceCounted, private base::NonCopyable 00039 { 00040 public: 00041 typedef intrusive_ptr<librpmDb> Ptr; 00042 typedef intrusive_ptr<const librpmDb> constPtr; 00043 private: 00053 static void dbAccess( librpmDb::Ptr & ptr_r ); 00054 00055 public: 00056 00058 // 00059 // static interface 00060 // 00062 private: 00063 00068 static Pathname _defaultRoot; 00069 00074 static Pathname _defaultDbPath; 00075 00079 static librpmDb::constPtr _defaultDb; 00080 00084 static bool _dbBlocked; 00085 00093 static librpmDb * newLibrpmDb( Pathname root_r, Pathname dbPath_r, bool readonly_r ); 00094 00107 static void dbAccess(); 00108 00109 public: 00110 00117 static bool globalInit(); 00118 00122 static std::string expand( const std::string & macro_r ); 00123 00127 static std::string stringPath( const Pathname & root_r, const Pathname & sub_r ) 00128 { 00129 return std::string( "'(" ) + root_r.asString() + ")" + sub_r.asString() + "'"; 00130 } 00131 00132 public: 00133 00137 static const Pathname & defaultRoot() 00138 { 00139 return _defaultRoot; 00140 } 00141 00145 static const Pathname & defaultDbPath() 00146 { 00147 return _defaultDbPath; 00148 } 00149 00164 static void dbAccess( const Pathname & root_r, const Pathname & dbPath_r ); 00165 00175 static void dbAccess( librpmDb::constPtr & ptr_r ); 00176 00189 static unsigned dbRelease( bool force_r = false ); 00190 00198 static unsigned blockAccess(); 00199 00210 static void unblockAccess(); 00211 00215 static bool isBlocked() 00216 { 00217 return _dbBlocked; 00218 } 00219 00223 static std::ostream & dumpState( std::ostream & str ); 00224 00225 public: 00226 00231 class DbDirInfo; 00232 00236 class db_const_iterator; 00237 00238 private: 00240 // 00241 // internal database handle interface (nonstatic) 00242 // 00244 00248 class D; 00249 D & _d; 00250 00251 protected: 00252 00257 librpmDb( const Pathname & root_r, const Pathname & dbPath_r, bool readonly_r ); 00258 00262 virtual void unref_to( unsigned refCount_r ) const; 00263 00264 public: 00265 00269 virtual ~librpmDb(); 00270 00274 const Pathname & root() const; 00275 00279 const Pathname & dbPath() const; 00280 00285 shared_ptr<RpmException> error() const; 00286 00290 bool valid() const 00291 { 00292 return( ! error() ); 00293 } 00294 00298 bool empty() const; 00299 00303 unsigned size() const; 00304 00305 public: 00306 00310 void * dont_call_it() const; 00311 00315 virtual std::ostream & dumpOn( std::ostream & str ) const; 00316 }; 00317 00319 00321 // 00322 // CLASS NAME : librpmDb::DbDirInfo 00327 class librpmDb::DbDirInfo 00328 { 00329 friend std::ostream & operator<<( std::ostream & str, const DbDirInfo & obj ); 00330 00331 private: 00332 00336 Pathname _root; 00337 00341 Pathname _dbPath; 00342 00346 PathInfo _dbDir; 00347 00351 PathInfo _dbV4; 00352 00356 PathInfo _dbV3; 00357 00361 PathInfo _dbV3ToV4; 00362 00363 public: 00364 00369 DbDirInfo( const Pathname & root_r, const Pathname & dbPath_r ); 00370 00371 public: 00372 00376 const Pathname & root() const 00377 { 00378 return _root; 00379 } 00380 00384 const Pathname & dbPath() const 00385 { 00386 return _dbPath; 00387 } 00388 00392 const PathInfo & dbDir() const 00393 { 00394 return _dbDir; 00395 } 00396 00400 const PathInfo & dbV4() const 00401 { 00402 return _dbV4; 00403 } 00404 00408 const PathInfo & dbV3() const 00409 { 00410 return _dbV3; 00411 } 00412 00416 const PathInfo & dbV3ToV4() const 00417 { 00418 return _dbV3ToV4; 00419 } 00420 00421 public: 00422 00426 void restat(); 00427 00428 public: 00429 00433 bool illegalArgs() const 00434 { 00435 return _dbDir.path().empty(); 00436 } 00437 00442 bool usableArgs() const 00443 { 00444 return _dbDir.isDir() || ! ( _dbDir.path().empty() || _dbDir.isExist() ); 00445 } 00446 00450 bool hasDbDir() const 00451 { 00452 return _dbDir.isDir(); 00453 } 00454 00458 bool hasDbV4() const 00459 { 00460 return _dbV4.isFile(); 00461 } 00462 00466 bool hasDbV3() const 00467 { 00468 return _dbV3.isFile(); 00469 } 00470 00474 bool hasDbV3ToV4() const 00475 { 00476 return _dbV3ToV4.isFile(); 00477 } 00478 }; 00479 00481 00483 // 00484 // CLASS NAME : librpmDb::db_const_iterator 00490 class librpmDb::db_const_iterator 00491 { 00492 db_const_iterator & operator=( const db_const_iterator & ); // NO ASSIGNMENT! 00493 db_const_iterator ( const db_const_iterator & ); // NO COPY! 00494 friend std::ostream & operator<<( std::ostream & str, const db_const_iterator & obj ); 00495 friend class librpmDb; 00496 00497 private: 00498 00502 class D; 00503 D & _d; 00504 00505 public: 00506 00513 db_const_iterator( librpmDb::constPtr dbptr_r = 0 ); 00514 00518 ~db_const_iterator(); 00519 00527 shared_ptr<RpmException> dbError() const; 00528 00532 void operator++(); 00533 00538 unsigned dbHdrNum() const; 00539 00544 const RpmHeader::constPtr & operator*() const; 00545 00549 const RpmHeader::constPtr & operator->() const 00550 { 00551 return operator*(); 00552 } 00553 00554 public: 00555 00564 bool findAll(); 00565 00569 bool findByFile( const std::string & file_r ); 00570 00574 bool findByProvides( const std::string & tag_r ); 00575 00579 bool findByRequiredBy( const std::string & tag_r ); 00580 00584 bool findByConflicts( const std::string & tag_r ); 00585 00596 bool findByName( const std::string & name_r ); 00597 00598 public: 00599 00607 bool findPackage( const std::string & name_r ); 00608 00613 bool findPackage( const std::string & name_r, const Edition & ed_r ); 00614 00618 bool findPackage( const Package::constPtr & which_r ); 00619 }; 00620 00622 } //namespace rpm 00623 } //namespace target 00624 } // namespace zypp 00625 00626 #endif // librpmDb_h 00627