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/KeyRing.h"
00028
00029 #include "zypp/target/rpm/RpmHeader.h"
00030 #include "zypp/target/rpm/RpmCallbacks.h"
00031 #include "zypp/ZYppCallbacks.h"
00032
00033 namespace zypp
00034 {
00035 namespace target
00036 {
00037 namespace rpm
00038 {
00039
00041
00042
00046 class RpmDb : public base::ReferenceCounted, private base::NonCopyable
00047 {
00048 public:
00049
00053 typedef class InstTargetError Error;
00054
00056
00057
00058
00060 private:
00061
00062 enum DbStateInfoBits {
00063 DbSI_NO_INIT = 0x0000,
00064 DbSI_HAVE_V4 = 0x0001,
00065 DbSI_MADE_V4 = 0x0002,
00066 DbSI_MODIFIED_V4 = 0x0004,
00067 DbSI_HAVE_V3 = 0x0008,
00068 DbSI_HAVE_V3TOV4 = 0x0010,
00069 DbSI_MADE_V3TOV4 = 0x0020
00070 };
00071
00072 friend std::ostream & operator<<( std::ostream & str, const DbStateInfoBits & obj );
00073
00074 void dbsi_set( DbStateInfoBits & val_r, const unsigned & bits_r ) const
00075 {
00076 val_r = (DbStateInfoBits)(val_r | bits_r);
00077 }
00078 void dbsi_clr( DbStateInfoBits & val_r, const unsigned & bits_r ) const
00079 {
00080 val_r = (DbStateInfoBits)(val_r & ~bits_r);
00081 }
00082 bool dbsi_has( const DbStateInfoBits & val_r, const unsigned & bits_r ) const
00083 {
00084 return( (val_r & bits_r) == bits_r );
00085 }
00086
00090 DbStateInfoBits _dbStateInfo;
00091
00095 Pathname _root;
00096
00100 Pathname _dbPath;
00101
00108 void 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 Date timestamp() const;
00146
00150 const Pathname & root() const
00151 {
00152 return _root;
00153 }
00154
00158 const Pathname & dbPath() const
00159 {
00160 return _dbPath;
00161 }
00162
00166 bool initialized() const
00167 {
00168 return( ! _root.empty() );
00169 }
00170
00193 void initDatabase( Pathname root_r = Pathname(),
00194 Pathname dbPath_r = Pathname() );
00195
00204 void closeDatabase();
00205
00212 void rebuildDatabase();
00213
00220 void importPubkey( const PublicKey & pubkey_r );
00221
00225 std::list<PublicKey> pubkeys() const;
00226
00230 std::set<Edition> pubkeyEditions() const;
00231
00233
00234
00235
00237 private:
00238
00239 class Packages;
00240
00241 Packages & _packages;
00242
00243 std::set<std::string> _filerequires;
00244
00245 public:
00246
00252 bool packagesValid() const;
00253
00257 const std::list<Package::Ptr> & getPackages();
00258
00260
00261
00262
00264 public:
00265
00271 std::list<FileInfo> fileList( const std::string & name_r, const Edition & edition_r ) const;
00272
00277 bool hasFile( const std::string & file_r, const std::string & name_r = "" ) const;
00278
00283 std::string whoOwnsFile( const std::string & file_r ) const;
00284
00288 bool hasProvides( const std::string & tag_r ) const;
00289
00293 bool hasRequiredBy( const std::string & tag_r ) const;
00294
00298 bool hasConflicts( const std::string & tag_r ) const;
00299
00303 bool hasPackage( const std::string & name_r ) const;
00304
00308 bool hasPackage( const std::string & name_r, const Edition & ed_r ) const;
00309
00321 void getData( const std::string & name_r,
00322 RpmHeader::constPtr & result_r ) const;
00323
00333 void getData( const std::string & name_r, const Edition & ed_r,
00334 RpmHeader::constPtr & result_r ) const;
00335
00336
00342 static Package::Ptr makePackageFromHeader( const RpmHeader::constPtr header,
00343 std::set<std::string> * filerequires,
00344 const Pathname & location, Repository repo );
00345
00347
00349 public:
00354 void importZyppKeyRingTrustedKeys();
00358 void exportTrustedKeysInZyppKeyRing();
00359 private:
00363 ExternalProgram *process;
00364
00365 typedef std::vector<const char*> RpmArgVec;
00366
00376 void run_rpm( const RpmArgVec& options,
00377 ExternalProgram::Stderr_Disposition stderr_disp =
00378 ExternalProgram::Stderr_To_Stdout);
00379
00380
00384 bool systemReadLine(std::string &line);
00385
00390 int systemStatus();
00391
00395 void systemKill();
00396
00400 int exit_code;
00401
00403 Pathname _backuppath;
00404
00406 bool _packagebackups;
00407
00409 bool _warndirexists;
00410
00420 void processConfigFiles(const std::string& line,
00421 const std::string& name,
00422 const char* typemsg,
00423 const char* difffailmsg,
00424 const char* diffgenmsg);
00425
00426
00427 public:
00428
00429 typedef std::set<std::string> FileList;
00430
00437 enum RpmInstFlag
00438 {
00439 RPMINST_NONE = 0x0000,
00440 RPMINST_NODOCS = 0x0001,
00441 RPMINST_NOSCRIPTS = 0x0002,
00442 RPMINST_FORCE = 0x0004,
00443 RPMINST_NODEPS = 0x0008,
00444 RPMINST_IGNORESIZE = 0x0010,
00445 RPMINST_JUSTDB = 0x0020,
00446 RPMINST_NODIGEST = 0x0040,
00447 RPMINST_NOSIGNATURE= 0x0080,
00448 RPMINST_NOUPGRADE = 0x0100,
00449 RPMINST_TEST = 0x0200
00450 };
00451
00456 enum checkPackageResult
00457 {
00458 CHK_OK = 0,
00459 CHK_NOTFOUND = 1,
00460 CHK_FAIL = 2,
00461 CHK_NOTTRUSTED = 3,
00462 CHK_NOKEY = 4,
00463 CHK_ERROR = 5
00464 };
00465
00473 checkPackageResult checkPackage( const Pathname & path_r );
00474
00485 void installPackage (const Pathname& filename, unsigned flags = 0 );
00486
00497 void removePackage(const std::string & name_r, unsigned flags = 0);
00498 void removePackage(Package::constPtr package, unsigned flags = 0);
00499
00504 Pathname getBackupPath (void)
00505 {
00506 return _backuppath;
00507 }
00508
00516 bool backupPackage(const std::string& packageName);
00517
00524 bool backupPackage(const Pathname& filename);
00525
00531 void setBackupPath(const Pathname& path);
00532
00539 void createPackageBackups(bool yes)
00540 {
00541 _packagebackups = yes;
00542 }
00543
00554 bool queryChangedFiles(FileList & fileList, const std::string& packageName);
00555
00556 public:
00557
00561 virtual std::ostream & dumpOn( std::ostream & str ) const;
00562
00563 protected:
00564 void doRemovePackage( const std::string & name_r, unsigned flags, callback::SendReport<RpmRemoveReport> & report );
00565 void doInstallPackage( const Pathname & filename, unsigned flags, callback::SendReport<RpmInstallReport> & report );
00566 const std::list<Package::Ptr> & doGetPackages(callback::SendReport<ScanDBReport> & report);
00567 void doRebuildDatabase(callback::SendReport<RebuildDBReport> & report);
00568
00569
00570 };
00571
00572 }
00573 }
00574 }
00575
00576 #endif // ZYPP_TARGET_RPM_RPMDB_H