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/Source.h"
00028 #include "zypp/KeyRing.h"
00029 
00030 #include "zypp/target/rpm/RpmHeader.h"
00031 #include "zypp/target/rpm/RpmCallbacks.h"
00032 #include "zypp/ZYppCallbacks.h"
00033 
00034 namespace zypp {
00035   namespace target {
00036     namespace rpm {
00037       
00039       //
00040       //        CLASS NAME : RpmDb
00044       class RpmDb : public base::ReferenceCounted, private base::NonCopyable
00045       {
00046         public:
00047       
00051           typedef class InstTargetError Error;
00052       
00054           //
00055           // INITALISATION
00056           //
00058         private:
00059       
00060           enum DbStateInfoBits {
00061             DbSI_NO_INIT        = 0x0000,
00062             DbSI_HAVE_V4        = 0x0001,
00063             DbSI_MADE_V4        = 0x0002,
00064             DbSI_MODIFIED_V4    = 0x0004,
00065             DbSI_HAVE_V3        = 0x0008,
00066             DbSI_HAVE_V3TOV4    = 0x0010,
00067             DbSI_MADE_V3TOV4    = 0x0020
00068           };
00069       
00070           friend std::ostream & operator<<( std::ostream & str, const DbStateInfoBits & obj );
00071       
00072           void dbsi_set( DbStateInfoBits & val_r, const unsigned & bits_r ) const {
00073             val_r = (DbStateInfoBits)(val_r | bits_r);
00074           }
00075           void dbsi_clr( DbStateInfoBits & val_r, const unsigned & bits_r ) const {
00076             val_r = (DbStateInfoBits)(val_r & ~bits_r);
00077           }
00078           bool dbsi_has( const DbStateInfoBits & val_r, const unsigned & bits_r ) const {
00079             return( (val_r & bits_r) == bits_r );
00080           }
00081       
00085           DbStateInfoBits _dbStateInfo;
00086       
00090           Pathname _root;
00091       
00095           Pathname _dbPath;
00096       
00103           void internal_initDatabase( const Pathname & root_r, const Pathname & dbPath_r,
00104                                    DbStateInfoBits & info_r );
00105       
00110           static void removeV4( const Pathname & dbdir_r, bool v3backup_r );
00111       
00116           static void removeV3( const Pathname & dbdir_r, bool v3backup_r );
00117       
00122           void modifyDatabase();
00123       
00124         public:
00125       
00130           RpmDb();
00131       
00135           ~RpmDb();
00136           
00140           const Pathname & root() const { return _root; }
00141       
00145           const Pathname & dbPath() const { return _dbPath; }
00146       
00150           bool initialized() const { return( ! _root.empty() ); }
00151       
00174           void initDatabase( Pathname root_r = Pathname(),
00175                           Pathname dbPath_r = Pathname() );
00176       
00185           void closeDatabase();
00186       
00193           void rebuildDatabase();
00194       
00201           void importPubkey( const Pathname & pubkey_r );
00202       
00206           std::list<PublicKey> pubkeys() const;
00207           
00211           std::set<Edition> pubkeyEditions() const;
00212       
00214           //
00215           // Cached RPM database retrieval via librpm.
00216           //
00218         private:
00219       
00220           class Packages;
00221       
00222           Packages & _packages;
00223       
00224           std::set<std::string> _filerequires;
00225       
00226         public:
00227       
00233           bool packagesValid() const;
00234       
00238           const std::list<Package::Ptr> & getPackages();
00239       
00240      #warning uncomment
00241 #if 0 
00242 
00245           void traceFileRel( const PkgRelation & rel_r );
00246 #endif
00247       
00249           //
00250           // Direct RPM database retrieval via librpm.
00251           //
00253         public:
00254 
00260           std::list<FileInfo> fileList( const std::string & name_r, const Edition & edition_r ) const;
00261 
00266           bool hasFile( const std::string & file_r, const std::string & name_r = "" ) const;
00267       
00272           std::string whoOwnsFile( const std::string & file_r ) const;
00273       
00277           bool hasProvides( const std::string & tag_r ) const;
00278       
00282           bool hasRequiredBy( const std::string & tag_r ) const;
00283       
00287           bool hasConflicts( const std::string & tag_r ) const;
00288       
00292           bool hasPackage( const std::string & name_r ) const;
00293       
00305           void getData( const std::string & name_r,
00306                      RpmHeader::constPtr & result_r ) const;
00307       
00317           void getData( const std::string & name_r, const Edition & ed_r,
00318                      RpmHeader::constPtr & result_r ) const;
00319       
00320 
00326           static Package::Ptr makePackageFromHeader( const RpmHeader::constPtr header, std::set<std::string> * filerequires, const Pathname & location, Source_Ref source );
00327 
00329           //
00331         public:
00336           void importZyppKeyRingTrustedKeys();
00340           void exportTrustedKeysInZyppKeyRing();
00341         private:  
00345           ExternalProgram *process;
00346       
00347           typedef std::vector<const char*> RpmArgVec;
00348       
00358           void run_rpm( const RpmArgVec& options,
00359                   ExternalProgram::Stderr_Disposition stderr_disp =
00360                   ExternalProgram::Stderr_To_Stdout);
00361       
00362       
00366           bool systemReadLine(std::string &line);
00367       
00372           int systemStatus();
00373       
00377           void systemKill();
00378       
00382           int exit_code;
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       
00419           enum RpmInstFlag
00420             {
00421               RPMINST_NONE       = 0x0000,
00422               RPMINST_NODOCS     = 0x0001,
00423               RPMINST_NOSCRIPTS  = 0x0002,
00424               RPMINST_FORCE      = 0x0004,
00425               RPMINST_NODEPS     = 0x0008,
00426               RPMINST_IGNORESIZE = 0x0010,
00427               RPMINST_JUSTDB     = 0x0020,
00428               RPMINST_NODIGEST   = 0x0040,
00429               RPMINST_NOSIGNATURE= 0x0080,
00430               RPMINST_NOUPGRADE  = 0x0100,
00431               RPMINST_TEST       = 0x0200
00432             };
00433       
00439           enum checkPackageResult
00440             {
00441             CHK_OK                = 0x00,
00442             CHK_INCORRECT_VERSION = 0x01, // package does not contain expected version
00443             CHK_INCORRECT_FILEMD5 = 0x02, // md5sum of file is wrong (outside)
00444             CHK_GPGSIG_MISSING    = 0x04, // package is not signeed
00445             CHK_MD5SUM_MISSING    = 0x08, // package is not signeed
00446             CHK_INCORRECT_GPGSIG  = 0x10, // signature incorrect
00447             CHK_INCORRECT_PKGMD5  = 0x20, // md5sum incorrect (inside)
00448             CHK_OTHER_FAILURE     = 0x40  // rpm failed for some reason
00449             };
00450       
00451       
00461           unsigned checkPackage (const Pathname& filename, std::string version = "", std::string md5 = "" );
00462       
00473           void installPackage (const Pathname& filename, unsigned flags = 0 );
00474       
00485           void removePackage(const std::string & name_r, unsigned flags = 0);
00486           void removePackage(Package::constPtr package, unsigned flags = 0);
00487       
00492           Pathname getBackupPath (void) { return _backuppath; }
00493       
00501           bool backupPackage(const std::string& packageName);
00502       
00509           bool backupPackage(const Pathname& filename);
00510       
00516           void setBackupPath(const Pathname& path);
00517       
00524           void createPackageBackups(bool yes) { _packagebackups = yes; }
00525       
00536           bool queryChangedFiles(FileList & fileList, const std::string& packageName);
00537       
00538         public: // static members
00539       
00543           static std::string checkPackageResult2string(unsigned code);
00544       
00545         public:
00546       
00550           virtual std::ostream & dumpOn( std::ostream & str ) const;
00551       
00553           //
00554           // Installation log
00555           //
00557         private:
00558       
00562           class Logfile;
00563       
00564         public:
00565       
00569           static bool setInstallationLogfile( const Pathname & filename );
00570 
00571         protected:
00572           void doRemovePackage( const std::string & name_r, unsigned flags, callback::SendReport<RpmRemoveReport> & report );
00573           void doInstallPackage( const Pathname & filename, unsigned flags, callback::SendReport<RpmInstallReport> & report );
00574           const std::list<Package::Ptr> & doGetPackages(callback::SendReport<ScanDBReport> & report);
00575           void doRebuildDatabase(callback::SendReport<RebuildDBReport> & report);
00576           
00577       
00578       };
00579 
00580     } // namespace rpm
00581   } // namespace target
00582 } // namespace zypp
00583 
00584 #endif // ZYPP_TARGET_RPM_RPMDB_H

Generated on Thu Jul 6 00:07:26 2006 for zypp by  doxygen 1.4.6