libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00013 // -*- C++ -*- 00014 00015 #ifndef ZYPP_TARGET_RPM_RPMDB_H 00016 #define ZYPP_TARGET_RPM_RPMDB_H 00017 00018 #include <iosfwd> 00019 #include <list> 00020 #include <vector> 00021 #include <string> 00022 00023 #include "zypp/Pathname.h" 00024 #include "zypp/ExternalProgram.h" 00025 00026 #include "zypp/Package.h" 00027 #include "zypp/KeyRing.h" 00028 00029 #include "zypp/target/rpm/RpmFlags.h" 00030 #include "zypp/target/rpm/RpmHeader.h" 00031 #include "zypp/target/rpm/RpmCallbacks.h" 00032 #include "zypp/ZYppCallbacks.h" 00033 00034 namespace zypp 00035 { 00036 namespace target 00037 { 00038 namespace rpm 00039 { 00040 00042 // 00043 // CLASS NAME : RpmDb 00047 class RpmDb : public base::ReferenceCounted, private base::NonCopyable 00048 { 00049 public: 00050 00054 typedef class InstTargetError Error; 00055 00057 // 00058 // INITALISATION 00059 // 00061 private: 00062 00063 enum DbStateInfoBits { 00064 DbSI_NO_INIT = 0x0000, 00065 DbSI_HAVE_V4 = 0x0001, 00066 DbSI_MADE_V4 = 0x0002, 00067 DbSI_MODIFIED_V4 = 0x0004, 00068 DbSI_HAVE_V3 = 0x0008, 00069 DbSI_HAVE_V3TOV4 = 0x0010, 00070 DbSI_MADE_V3TOV4 = 0x0020 00071 }; 00072 00073 friend std::ostream & operator<<( std::ostream & str, const DbStateInfoBits & obj ); 00074 00075 void dbsi_set( DbStateInfoBits & val_r, const unsigned & bits_r ) const 00076 { 00077 val_r = (DbStateInfoBits)(val_r | bits_r); 00078 } 00079 void dbsi_clr( DbStateInfoBits & val_r, const unsigned & bits_r ) const 00080 { 00081 val_r = (DbStateInfoBits)(val_r & ~bits_r); 00082 } 00083 bool dbsi_has( const DbStateInfoBits & val_r, const unsigned & bits_r ) const 00084 { 00085 return( (val_r & bits_r) == bits_r ); 00086 } 00087 00091 DbStateInfoBits _dbStateInfo; 00092 00096 Pathname _root; 00097 00101 Pathname _dbPath; 00102 00109 void internal_initDatabase( const Pathname & root_r, const Pathname & dbPath_r, 00110 DbStateInfoBits & info_r ); 00111 00116 static void removeV4( const Pathname & dbdir_r, bool v3backup_r ); 00117 00122 static void removeV3( const Pathname & dbdir_r, bool v3backup_r ); 00123 00128 void modifyDatabase(); 00129 00130 public: 00131 00136 RpmDb(); 00137 00141 ~RpmDb(); 00142 00146 Date timestamp() const; 00147 00151 const Pathname & root() const 00152 { 00153 return _root; 00154 } 00155 00159 const Pathname & dbPath() const 00160 { 00161 return _dbPath; 00162 } 00163 00167 bool initialized() const 00168 { 00169 return( ! _root.empty() ); 00170 } 00171 00197 void initDatabase( Pathname root_r = Pathname(), 00198 Pathname dbPath_r = Pathname(), 00199 bool doRebuild_r = false ); 00200 00209 void closeDatabase(); 00210 00217 void rebuildDatabase(); 00218 00225 void importPubkey( const PublicKey & pubkey_r ); 00226 00233 void removePubkey( const PublicKey & pubkey_r ); 00234 00238 std::list<PublicKey> pubkeys() const; 00239 00243 std::set<Edition> pubkeyEditions() const; 00244 00246 // 00247 // Direct RPM database retrieval via librpm. 00248 // 00250 public: 00251 00257 std::list<FileInfo> fileList( const std::string & name_r, const Edition & edition_r ) const; 00258 00263 bool hasFile( const std::string & file_r, const std::string & name_r = "" ) const; 00264 00269 std::string whoOwnsFile( const std::string & file_r ) const; 00270 00274 bool hasProvides( const std::string & tag_r ) const; 00275 00279 bool hasRequiredBy( const std::string & tag_r ) const; 00280 00284 bool hasConflicts( const std::string & tag_r ) const; 00285 00289 bool hasPackage( const std::string & name_r ) const; 00290 00294 bool hasPackage( const std::string & name_r, const Edition & ed_r ) const; 00295 00307 void getData( const std::string & name_r, 00308 RpmHeader::constPtr & result_r ) const; 00309 00319 void getData( const std::string & name_r, const Edition & ed_r, 00320 RpmHeader::constPtr & result_r ) const; 00321 00323 // 00325 public: 00330 void importZyppKeyRingTrustedKeys(); 00334 void exportTrustedKeysInZyppKeyRing(); 00335 private: 00339 ExternalProgram *process; 00340 00341 typedef std::vector<const char*> RpmArgVec; 00342 00352 void run_rpm( const RpmArgVec& options, 00353 ExternalProgram::Stderr_Disposition stderr_disp = 00354 ExternalProgram::Stderr_To_Stdout); 00355 00356 00360 bool systemReadLine(std::string &line); 00361 00366 int systemStatus(); 00367 00371 void systemKill(); 00372 00376 int exit_code; 00377 00382 std::string error_message; 00383 00385 Pathname _backuppath; 00386 00388 bool _packagebackups; 00389 00391 bool _warndirexists; 00392 00402 void processConfigFiles(const std::string& line, 00403 const std::string& name, 00404 const char* typemsg, 00405 const char* difffailmsg, 00406 const char* diffgenmsg); 00407 00408 00409 public: 00410 00411 typedef std::set<std::string> FileList; 00412 00417 enum checkPackageResult 00418 { 00419 CHK_OK = 0, 00420 CHK_NOTFOUND = 1, 00421 CHK_FAIL = 2, 00422 CHK_NOTTRUSTED = 3, 00423 CHK_NOKEY = 4, 00424 CHK_ERROR = 5 00425 }; 00426 00434 checkPackageResult checkPackage( const Pathname & path_r ); 00435 00446 void installPackage ( const Pathname & filename, RpmInstFlags flags = RPMINST_NONE ); 00447 00458 void removePackage( const std::string & name_r, RpmInstFlags flags = RPMINST_NONE ); 00459 void removePackage( Package::constPtr package, RpmInstFlags flags = RPMINST_NONE ); 00460 00465 Pathname getBackupPath (void) 00466 { 00467 return _backuppath; 00468 } 00469 00477 bool backupPackage(const std::string& packageName); 00478 00485 bool backupPackage(const Pathname& filename); 00486 00492 void setBackupPath(const Pathname& path); 00493 00500 void createPackageBackups(bool yes) 00501 { 00502 _packagebackups = yes; 00503 } 00504 00515 bool queryChangedFiles(FileList & fileList, const std::string& packageName); 00516 00517 public: 00518 00522 virtual std::ostream & dumpOn( std::ostream & str ) const; 00523 00524 protected: 00525 void doRemovePackage( const std::string & name_r, RpmInstFlags flags, callback::SendReport<RpmRemoveReport> & report ); 00526 void doInstallPackage( const Pathname & filename, RpmInstFlags flags, callback::SendReport<RpmInstallReport> & report ); 00527 void doRebuildDatabase(callback::SendReport<RebuildDBReport> & report); 00528 }; 00529 00530 } // namespace rpm 00531 } // namespace target 00532 } // namespace zypp 00533 00534 #endif // ZYPP_TARGET_RPM_RPMDB_H