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 
00297           bool hasPackage( const std::string & name_r, const Edition & ed_r ) const;
00298 
00310           void getData( const std::string & name_r,
00311                      RpmHeader::constPtr & result_r ) const;
00312 
00322           void getData( const std::string & name_r, const Edition & ed_r,
00323                      RpmHeader::constPtr & result_r ) const;
00324 
00325 
00331           static Package::Ptr makePackageFromHeader( const RpmHeader::constPtr header, std::set<std::string> * filerequires, const Pathname & location, Source_Ref source );
00332 
00334           //
00336         public:
00341           void importZyppKeyRingTrustedKeys();
00345           void exportTrustedKeysInZyppKeyRing();
00346         private:
00350           ExternalProgram *process;
00351 
00352           typedef std::vector<const char*> RpmArgVec;
00353 
00363           void run_rpm( const RpmArgVec& options,
00364                   ExternalProgram::Stderr_Disposition stderr_disp =
00365                   ExternalProgram::Stderr_To_Stdout);
00366 
00367 
00371           bool systemReadLine(std::string &line);
00372 
00377           int systemStatus();
00378 
00382           void systemKill();
00383 
00387           int exit_code;
00388 
00390           Pathname _backuppath;
00391 
00393           bool _packagebackups;
00394 
00396           bool _warndirexists;
00397 
00407           void processConfigFiles(const std::string& line,
00408                              const std::string& name,
00409                              const char* typemsg,
00410                              const char* difffailmsg,
00411                              const char* diffgenmsg);
00412 
00413 
00414         public:
00415 
00416           typedef std::set<std::string> FileList;
00417 
00424           enum RpmInstFlag
00425             {
00426               RPMINST_NONE       = 0x0000,
00427               RPMINST_NODOCS     = 0x0001,
00428               RPMINST_NOSCRIPTS  = 0x0002,
00429               RPMINST_FORCE      = 0x0004,
00430               RPMINST_NODEPS     = 0x0008,
00431               RPMINST_IGNORESIZE = 0x0010,
00432               RPMINST_JUSTDB     = 0x0020,
00433               RPMINST_NODIGEST   = 0x0040,
00434               RPMINST_NOSIGNATURE= 0x0080,
00435               RPMINST_NOUPGRADE  = 0x0100,
00436               RPMINST_TEST       = 0x0200
00437             };
00438 
00444           enum checkPackageResult
00445             {
00446             CHK_OK                = 0x00,
00447             CHK_INCORRECT_VERSION = 0x01, // package does not contain expected version
00448             CHK_INCORRECT_FILEMD5 = 0x02, // md5sum of file is wrong (outside)
00449             CHK_GPGSIG_MISSING    = 0x04, // package is not signeed
00450             CHK_MD5SUM_MISSING    = 0x08, // package is not signeed
00451             CHK_INCORRECT_GPGSIG  = 0x10, // signature incorrect
00452             CHK_INCORRECT_PKGMD5  = 0x20, // md5sum incorrect (inside)
00453             CHK_OTHER_FAILURE     = 0x40  // rpm failed for some reason
00454             };
00455 
00456 
00466           unsigned checkPackage (const Pathname& filename, std::string version = "", std::string md5 = "" );
00467 
00478           void installPackage (const Pathname& filename, unsigned flags = 0 );
00479 
00490           void removePackage(const std::string & name_r, unsigned flags = 0);
00491           void removePackage(Package::constPtr package, unsigned flags = 0);
00492 
00497           Pathname getBackupPath (void) { return _backuppath; }
00498 
00506           bool backupPackage(const std::string& packageName);
00507 
00514           bool backupPackage(const Pathname& filename);
00515 
00521           void setBackupPath(const Pathname& path);
00522 
00529           void createPackageBackups(bool yes) { _packagebackups = yes; }
00530 
00541           bool queryChangedFiles(FileList & fileList, const std::string& packageName);
00542 
00543         public: // static members
00544 
00548           static std::string checkPackageResult2string(unsigned code);
00549 
00550         public:
00551 
00555           virtual std::ostream & dumpOn( std::ostream & str ) const;
00556 
00558           //
00559           // Installation log
00560           //
00562         private:
00563 
00567           class Logfile;
00568 
00569         public:
00570 
00574           static bool setInstallationLogfile( const Pathname & filename );
00575 
00576         protected:
00577           void doRemovePackage( const std::string & name_r, unsigned flags, callback::SendReport<RpmRemoveReport> & report );
00578           void doInstallPackage( const Pathname & filename, unsigned flags, callback::SendReport<RpmInstallReport> & report );
00579           const std::list<Package::Ptr> & doGetPackages(callback::SendReport<ScanDBReport> & report);
00580           void doRebuildDatabase(callback::SendReport<RebuildDBReport> & report);
00581 
00582 
00583       };
00584 
00585     } // namespace rpm
00586   } // namespace target
00587 } // namespace zypp
00588 
00589 #endif // ZYPP_TARGET_RPM_RPMDB_H

Generated on Thu Sep 14 15:38:53 2006 for zypp by  doxygen 1.4.6