RpmDb.h

Go to the documentation of this file.
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:
00327   enum SyncTrustedKeyBits
00328   {
00329     SYNC_TO_KEYRING     = 1<<0, 
00330     SYNC_FROM_KEYRING   = 1<<1, 
00331     SYNC_BOTH           = SYNC_TO_KEYRING | SYNC_FROM_KEYRING
00332   };
00336   void syncTrustedKeys( SyncTrustedKeyBits mode_r = SYNC_BOTH );
00341   void importZyppKeyRingTrustedKeys();
00345   void exportTrustedKeysInZyppKeyRing();
00346 
00347 private:
00351   ExternalProgram *process;
00352 
00353   typedef std::vector<const char*> RpmArgVec;
00354 
00364   void run_rpm( const RpmArgVec& options,
00365                 ExternalProgram::Stderr_Disposition stderr_disp =
00366                   ExternalProgram::Stderr_To_Stdout);
00367 
00368 
00372   bool systemReadLine(std::string &line);
00373 
00378   int systemStatus();
00379 
00383   void systemKill();
00384 
00388   int exit_code;
00389 
00394   std::string error_message;
00395 
00397   Pathname _backuppath;
00398 
00400   bool _packagebackups;
00401 
00403   bool _warndirexists;
00404 
00414   void processConfigFiles(const std::string& line,
00415                           const std::string& name,
00416                           const char* typemsg,
00417                           const char* difffailmsg,
00418                           const char* diffgenmsg);
00419 
00420 
00421 public:
00422 
00423   typedef std::set<std::string> FileList;
00424 
00429   enum checkPackageResult
00430   {
00431     CHK_OK            = 0, 
00432     CHK_NOTFOUND      = 1, 
00433     CHK_FAIL          = 2, 
00434     CHK_NOTTRUSTED    = 3, 
00435     CHK_NOKEY         = 4, 
00436     CHK_ERROR         = 5  
00437   };
00438 
00446   checkPackageResult checkPackage( const Pathname & path_r );
00447 
00458   void installPackage ( const Pathname & filename, RpmInstFlags flags = RPMINST_NONE );
00459 
00470   void removePackage( const std::string & name_r, RpmInstFlags flags = RPMINST_NONE );
00471   void removePackage( Package::constPtr package, RpmInstFlags flags = RPMINST_NONE );
00472 
00477   Pathname getBackupPath (void)
00478   {
00479     return _backuppath;
00480   }
00481 
00489   bool backupPackage(const std::string& packageName);
00490 
00497   bool backupPackage(const Pathname& filename);
00498 
00504   void setBackupPath(const Pathname& path);
00505 
00512   void createPackageBackups(bool yes)
00513   {
00514     _packagebackups = yes;
00515   }
00516 
00527   bool queryChangedFiles(FileList & fileList, const std::string& packageName);
00528 
00529 public:
00530 
00534   virtual std::ostream & dumpOn( std::ostream & str ) const;
00535 
00536 protected:
00537   void doRemovePackage( const std::string & name_r, RpmInstFlags flags, callback::SendReport<RpmRemoveReport> & report );
00538   void doInstallPackage( const Pathname & filename, RpmInstFlags flags, callback::SendReport<RpmInstallReport> & report );
00539   void doRebuildDatabase(callback::SendReport<RebuildDBReport> & report);
00540 };
00541 
00542 } // namespace rpm
00543 } // namespace target
00544 } // namespace zypp
00545 
00546 #endif // ZYPP_TARGET_RPM_RPMDB_H

Generated on Tue May 5 14:43:20 2015 for libzypp by  doxygen 1.5.6