Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

RpmDb.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                                                                      |
00003 |                      __   __    ____ _____ ____                      |
00004 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00005 |                       \ V / _` \___ \ | |   __) |                    |
00006 |                        | | (_| |___) || |  / __/                     |
00007 |                        |_|\__,_|____/ |_| |_____|                    |
00008 |                                                                      |
00009 |                           Package Management                         |
00010 |                                                     (C) 2002 SuSE AG |
00011 \----------------------------------------------------------------------/
00012 
00013    File:       RpmDb.h
00014    Purpose:    Interface to installed RPM system
00015    Author:     Stefan Schubert  <schubi@suse.de>
00016    Maintainer: Ludwig Nussel <lnussel@suse.de>
00017 
00018    Copied and adapted from agent-targetpkg
00019 
00020 /-*/
00021 
00022 // -*- C++ -*-
00023 
00024 #ifndef RpmDb_h
00025 #define RpmDb_h
00026 
00027 #include <iosfwd>
00028 #include <list>
00029 #include <vector>
00030 #include <string>
00031 
00032 #include <y2util/Pathname.h>
00033 #include <y2util/ExternalProgram.h>
00034 
00035 #include <y2pm/RpmDbPtr.h>
00036 #include <y2pm/PMError.h>
00037 
00038 #include <y2pm/PMSolvable.h>
00039 #include <y2pm/PMPackagePtr.h>
00040 
00041 #include <y2pm/RpmHeaderPtr.h>
00042 #include <y2pm/FileDeps.h>
00043 
00045 //
00046 //      CLASS NAME : RpmDb
00050 class RpmDb: public CountedRep
00051 {
00052   REP_BODY(RpmDb);
00053 
00054   public:
00055 
00059     typedef class InstTargetError Error;
00060 
00062     //
00063     // INITALISATION
00064     //
00066   private:
00067 
00068     enum DbStateInfoBits {
00069       DbSI_NO_INIT      = 0x0000,
00070       DbSI_HAVE_V4      = 0x0001,
00071       DbSI_MADE_V4      = 0x0002,
00072       DbSI_MODIFIED_V4  = 0x0004,
00073       DbSI_HAVE_V3      = 0x0008,
00074       DbSI_HAVE_V3TOV4  = 0x0010,
00075       DbSI_MADE_V3TOV4  = 0x0020
00076     };
00077 
00078     friend std::ostream & operator<<( std::ostream & str, const DbStateInfoBits & obj );
00079 
00080     void dbsi_set( DbStateInfoBits & val_r, const unsigned & bits_r ) const {
00081       val_r = (DbStateInfoBits)(val_r | bits_r);
00082     }
00083     void dbsi_clr( DbStateInfoBits & val_r, const unsigned & bits_r ) const {
00084       val_r = (DbStateInfoBits)(val_r & ~bits_r);
00085     }
00086     bool dbsi_has( const DbStateInfoBits & val_r, const unsigned & bits_r ) const {
00087       return( (val_r & bits_r) == bits_r );
00088     }
00089 
00093     DbStateInfoBits _dbStateInfo;
00094 
00098     Pathname _root;
00099 
00103     Pathname _dbPath;
00104 
00108     PMError internal_initDatabase( const Pathname & root_r, const Pathname & dbPath_r,
00109                                    DbStateInfoBits & info_r );
00110 
00115     static void removeV4( const Pathname & dbdir_r, bool v3backup_r );
00116 
00121     static void removeV3( const Pathname & dbdir_r, bool v3backup_r );
00122 
00127     void modifyDatabase();
00128 
00129   public:
00130 
00135     RpmDb();
00136 
00140     ~RpmDb();
00141 
00145     const Pathname & root() const { return _root; }
00146 
00150     const Pathname & dbPath() const { return _dbPath; }
00151 
00155     bool initialized() const { return( ! _root.empty() ); }
00156 
00176     PMError initDatabase( Pathname root_r = Pathname(),
00177                           Pathname dbPath_r = Pathname() );
00178 
00184     PMError closeDatabase();
00185 
00189     PMError rebuildDatabase();
00190 
00194     PMError importPubkey( const Pathname & pubkey_r );
00195 
00199     PMError importPubkey( const Pathname & keyring_r, const std::string & keyname_r );
00200 
00204     std::set<PkgEdition> pubkeys() const;
00205 
00207     //
00208     // Cached RPM database retrieval via librpm.
00209     //
00211   private:
00212 
00213     class Packages;
00214 
00215     Packages & _packages;
00216 
00217     FileDeps::FileNames _filerequires;
00218 
00219   public:
00220 
00226     bool packagesValid() const;
00227 
00231     const std::list<PMPackagePtr> & getPackages();
00232 
00233 
00237     void traceFileRel( const PkgRelation & rel_r );
00238 
00240     //
00241     // Direct RPM database retrieval via librpm.
00242     //
00244   public:
00245 
00249     bool hasFile( const std::string & file_r ) const;
00250 
00254     bool hasProvides( const std::string & tag_r ) const;
00255 
00259     bool hasRequiredBy( const std::string & tag_r ) const;
00260 
00264     bool hasConflicts( const std::string & tag_r ) const;
00265 
00269     bool hasPackage( const PkgName & name_r ) const;
00270 
00277     PMError getData( const PkgName & name_r,
00278                      constRpmHeaderPtr & result_r ) const;
00279 
00286     PMError getData( const PkgName & name_r, const PkgEdition & ed_r,
00287                      constRpmHeaderPtr & result_r ) const;
00288 
00290     //
00292   private:
00293 
00297     ExternalProgram *process;
00298 
00299     typedef std::vector<const char*> RpmArgVec;
00300 
00307     void run_rpm( const RpmArgVec& options,
00308                   ExternalProgram::Stderr_Disposition stderr_disp =
00309                   ExternalProgram::Stderr_To_Stdout);
00310 
00311 
00315     bool systemReadLine(std::string &line);
00316 
00321     int systemStatus();
00322 
00326     void systemKill();
00327 
00331     int exit_code;
00332 
00334     Pathname _backuppath;
00335 
00337     bool _packagebackups;
00338 
00340     bool _warndirexists;
00341 
00351     void processConfigFiles(const std::string& line,
00352                              const std::string& name,
00353                              const char* typemsg,
00354                              const char* difffailmsg,
00355                              const char* diffgenmsg);
00356 
00357 
00358   public:
00359 
00360     typedef std::set<std::string> FileList;
00361 
00368     enum RpmInstFlag
00369       {
00370         RPMINST_NONE       = 0x00,
00371         RPMINST_NODOCS     = 0x01,
00372         RPMINST_NOSCRIPTS  = 0x02,
00373         RPMINST_FORCE      = 0x04,
00374         RPMINST_NODEPS     = 0x08,
00375         RPMINST_IGNORESIZE = 0x10,
00376         RPMINST_JUSTDB     = 0x20,
00377         RPMINST_NODIGEST   = 0x40,
00378         RPMINST_NOSIGNATURE= 0x80
00379       };
00380 
00386     enum checkPackageResult
00387       {
00388       CHK_OK                = 0x00,
00389       CHK_INCORRECT_VERSION = 0x01, // package does not contain expected version
00390       CHK_INCORRECT_FILEMD5 = 0x02, // md5sum of file is wrong (outside)
00391       CHK_GPGSIG_MISSING    = 0x04, // package is not signeed
00392       CHK_MD5SUM_MISSING    = 0x08, // package is not signeed
00393       CHK_INCORRECT_GPGSIG  = 0x10, // signature incorrect
00394       CHK_INCORRECT_PKGMD5  = 0x20, // md5sum incorrect (inside)
00395       CHK_OTHER_FAILURE     = 0x40  // rpm failed for some reason
00396       };
00397 
00398 
00408     unsigned checkPackage (const Pathname& filename, std::string version = "", std::string md5 = "" );
00409 
00417     PMError installPackage (const Pathname& filename, unsigned flags = 0 );
00418 
00426     PMError removePackage(const std::string & name_r, unsigned flags = 0);
00427     PMError removePackage(constPMPackagePtr package, unsigned flags = 0);
00428 
00433     Pathname getBackupPath (void) { return _backuppath; }
00434 
00442     bool backupPackage(const std::string& packageName);
00443 
00450     bool backupPackage(const Pathname& filename);
00451 
00457     void setBackupPath(const Pathname& path);
00458 
00465     void createPackageBackups(bool yes) { _packagebackups = yes; }
00466 
00477     bool queryChangedFiles(FileList & fileList, const std::string& packageName);
00478 
00479   public: // static members
00480 
00484     static std::string checkPackageResult2string(unsigned code);
00485 
00486   public:
00487 
00491     virtual std::ostream & dumpOn( std::ostream & str ) const;
00492 
00494     //
00495     // Installation log
00496     //
00498   private:
00499 
00503     class Logfile;
00504 
00505   public:
00506 
00510     static bool setInstallationLogfile( const Pathname & filename );
00511 
00512 };
00513 
00514 #endif // RpmDb_h

Generated on Fri Nov 9 14:30:32 2007 for yast2-packagemanager by doxygen 1.3.6