00001
00002
00003
00004
00005
00006
00007
00008
00013
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 {
00036 namespace target
00037 {
00038 namespace rpm
00039 {
00040
00042
00043
00047 class RpmDb : public base::ReferenceCounted, private base::NonCopyable
00048 {
00049 public:
00050
00054 typedef class InstTargetError Error;
00055
00057
00058
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
00194 void initDatabase( Pathname root_r = Pathname(),
00195 Pathname dbPath_r = Pathname() );
00196
00205 void closeDatabase();
00206
00213 void rebuildDatabase();
00214
00221 void importPubkey( const Pathname & pubkey_r );
00222
00226 std::list<PublicKey> pubkeys() const;
00227
00231 std::set<Edition> pubkeyEditions() const;
00232
00234
00235
00236
00238 private:
00239
00240 class Packages;
00241
00242 Packages & _packages;
00243
00244 std::set<std::string> _filerequires;
00245
00246 public:
00247
00253 bool packagesValid() const;
00254
00258 const std::list<Package::Ptr> & getPackages();
00259
00261
00262
00263
00265 public:
00266
00272 std::list<FileInfo> fileList( const std::string & name_r, const Edition & edition_r ) const;
00273
00278 bool hasFile( const std::string & file_r, const std::string & name_r = "" ) const;
00279
00284 std::string whoOwnsFile( const std::string & file_r ) const;
00285
00289 bool hasProvides( const std::string & tag_r ) const;
00290
00294 bool hasRequiredBy( const std::string & tag_r ) const;
00295
00299 bool hasConflicts( const std::string & tag_r ) const;
00300
00304 bool hasPackage( const std::string & name_r ) const;
00305
00309 bool hasPackage( const std::string & name_r, const Edition & ed_r ) const;
00310
00322 void getData( const std::string & name_r,
00323 RpmHeader::constPtr & result_r ) const;
00324
00334 void getData( const std::string & name_r, const Edition & ed_r,
00335 RpmHeader::constPtr & result_r ) const;
00336
00337
00343 static Package::Ptr makePackageFromHeader( const RpmHeader::constPtr header, std::set<std::string> * filerequires, const Pathname & location, Source_Ref source );
00344
00346
00348 public:
00353 void importZyppKeyRingTrustedKeys();
00357 void exportTrustedKeysInZyppKeyRing();
00358 private:
00362 ExternalProgram *process;
00363
00364 typedef std::vector<const char*> RpmArgVec;
00365
00375 void run_rpm( const RpmArgVec& options,
00376 ExternalProgram::Stderr_Disposition stderr_disp =
00377 ExternalProgram::Stderr_To_Stdout);
00378
00379
00383 bool systemReadLine(std::string &line);
00384
00389 int systemStatus();
00390
00394 void systemKill();
00395
00399 int exit_code;
00400
00402 Pathname _backuppath;
00403
00405 bool _packagebackups;
00406
00408 bool _warndirexists;
00409
00419 void processConfigFiles(const std::string& line,
00420 const std::string& name,
00421 const char* typemsg,
00422 const char* difffailmsg,
00423 const char* diffgenmsg);
00424
00425
00426 public:
00427
00428 typedef std::set<std::string> FileList;
00429
00436 enum RpmInstFlag
00437 {
00438 RPMINST_NONE = 0x0000,
00439 RPMINST_NODOCS = 0x0001,
00440 RPMINST_NOSCRIPTS = 0x0002,
00441 RPMINST_FORCE = 0x0004,
00442 RPMINST_NODEPS = 0x0008,
00443 RPMINST_IGNORESIZE = 0x0010,
00444 RPMINST_JUSTDB = 0x0020,
00445 RPMINST_NODIGEST = 0x0040,
00446 RPMINST_NOSIGNATURE= 0x0080,
00447 RPMINST_NOUPGRADE = 0x0100,
00448 RPMINST_TEST = 0x0200
00449 };
00450
00455 enum checkPackageResult
00456 {
00457 CHK_OK = 0,
00458 CHK_NOTFOUND = 1,
00459 CHK_FAIL = 2,
00460 CHK_NOTTRUSTED = 3,
00461 CHK_NOKEY = 4,
00462 CHK_ERROR = 5
00463 };
00464
00472 checkPackageResult checkPackage( const Pathname & path_r );
00473
00484 void installPackage (const Pathname& filename, unsigned flags = 0 );
00485
00496 void removePackage(const std::string & name_r, unsigned flags = 0);
00497 void removePackage(Package::constPtr package, unsigned flags = 0);
00498
00503 Pathname getBackupPath (void)
00504 {
00505 return _backuppath;
00506 }
00507
00515 bool backupPackage(const std::string& packageName);
00516
00523 bool backupPackage(const Pathname& filename);
00524
00530 void setBackupPath(const Pathname& path);
00531
00538 void createPackageBackups(bool yes)
00539 {
00540 _packagebackups = yes;
00541 }
00542
00553 bool queryChangedFiles(FileList & fileList, const std::string& packageName);
00554
00555 public:
00556
00560 virtual std::ostream & dumpOn( std::ostream & str ) const;
00561
00562 protected:
00563 void doRemovePackage( const std::string & name_r, unsigned flags, callback::SendReport<RpmRemoveReport> & report );
00564 void doInstallPackage( const Pathname & filename, unsigned flags, callback::SendReport<RpmInstallReport> & report );
00565 const std::list<Package::Ptr> & doGetPackages(callback::SendReport<ScanDBReport> & report);
00566 void doRebuildDatabase(callback::SendReport<RebuildDBReport> & report);
00567
00568
00569 };
00570
00571 }
00572 }
00573 }
00574
00575 #endif // ZYPP_TARGET_RPM_RPMDB_H