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
00229 void importPubkey( const PublicKey & pubkey_r );
00230
00234 std::list<PublicKey> pubkeys() const;
00235
00239 std::set<Edition> pubkeyEditions() const;
00240
00242
00243
00244
00246 private:
00247
00248 class Packages;
00249
00250 Packages & _packages;
00251
00252 std::set<std::string> _filerequires;
00253
00254 public:
00255
00261 bool packagesValid() const;
00262
00266 const std::list<Package::Ptr> & getPackages();
00267
00269
00270
00271
00273 public:
00274
00280 std::list<FileInfo> fileList( const std::string & name_r, const Edition & edition_r ) const;
00281
00286 bool hasFile( const std::string & file_r, const std::string & name_r = "" ) const;
00287
00292 std::string whoOwnsFile( const std::string & file_r ) const;
00293
00297 bool hasProvides( const std::string & tag_r ) const;
00298
00302 bool hasRequiredBy( const std::string & tag_r ) const;
00303
00307 bool hasConflicts( const std::string & tag_r ) const;
00308
00312 bool hasPackage( const std::string & name_r ) const;
00313
00317 bool hasPackage( const std::string & name_r, const Edition & ed_r ) const;
00318
00330 void getData( const std::string & name_r,
00331 RpmHeader::constPtr & result_r ) const;
00332
00342 void getData( const std::string & name_r, const Edition & ed_r,
00343 RpmHeader::constPtr & result_r ) const;
00344
00345
00351 static Package::Ptr makePackageFromHeader( const RpmHeader::constPtr header, std::set<std::string> * filerequires, const Pathname & location, Source_Ref source );
00352
00354
00356 public:
00361 void importZyppKeyRingTrustedKeys();
00365 void exportTrustedKeysInZyppKeyRing();
00366 private:
00370 ExternalProgram *process;
00371
00372 typedef std::vector<const char*> RpmArgVec;
00373
00383 void run_rpm( const RpmArgVec& options,
00384 ExternalProgram::Stderr_Disposition stderr_disp =
00385 ExternalProgram::Stderr_To_Stdout);
00386
00387
00391 bool systemReadLine(std::string &line);
00392
00397 int systemStatus();
00398
00402 void systemKill();
00403
00407 int exit_code;
00408
00410 Pathname _backuppath;
00411
00413 bool _packagebackups;
00414
00416 bool _warndirexists;
00417
00427 void processConfigFiles(const std::string& line,
00428 const std::string& name,
00429 const char* typemsg,
00430 const char* difffailmsg,
00431 const char* diffgenmsg);
00432
00433
00434 public:
00435
00436 typedef std::set<std::string> FileList;
00437
00444 enum RpmInstFlag
00445 {
00446 RPMINST_NONE = 0x0000,
00447 RPMINST_NODOCS = 0x0001,
00448 RPMINST_NOSCRIPTS = 0x0002,
00449 RPMINST_FORCE = 0x0004,
00450 RPMINST_NODEPS = 0x0008,
00451 RPMINST_IGNORESIZE = 0x0010,
00452 RPMINST_JUSTDB = 0x0020,
00453 RPMINST_NODIGEST = 0x0040,
00454 RPMINST_NOSIGNATURE= 0x0080,
00455 RPMINST_NOUPGRADE = 0x0100,
00456 RPMINST_TEST = 0x0200
00457 };
00458
00463 enum checkPackageResult
00464 {
00465 CHK_OK = 0,
00466 CHK_NOTFOUND = 1,
00467 CHK_FAIL = 2,
00468 CHK_NOTTRUSTED = 3,
00469 CHK_NOKEY = 4,
00470 CHK_ERROR = 5
00471 };
00472
00480 checkPackageResult checkPackage( const Pathname & path_r );
00481
00492 void installPackage (const Pathname& filename, unsigned flags = 0 );
00493
00504 void removePackage(const std::string & name_r, unsigned flags = 0);
00505 void removePackage(Package::constPtr package, unsigned flags = 0);
00506
00511 Pathname getBackupPath (void)
00512 {
00513 return _backuppath;
00514 }
00515
00523 bool backupPackage(const std::string& packageName);
00524
00531 bool backupPackage(const Pathname& filename);
00532
00538 void setBackupPath(const Pathname& path);
00539
00546 void createPackageBackups(bool yes)
00547 {
00548 _packagebackups = yes;
00549 }
00550
00561 bool queryChangedFiles(FileList & fileList, const std::string& packageName);
00562
00563 public:
00564
00568 virtual std::ostream & dumpOn( std::ostream & str ) const;
00569
00570 protected:
00571 void doRemovePackage( const std::string & name_r, unsigned flags, callback::SendReport<RpmRemoveReport> & report );
00572 void doInstallPackage( const Pathname & filename, unsigned flags, callback::SendReport<RpmInstallReport> & report );
00573 const std::list<Package::Ptr> & doGetPackages(callback::SendReport<ScanDBReport> & report);
00574 void doRebuildDatabase(callback::SendReport<RebuildDBReport> & report);
00575
00576
00577 };
00578
00579 }
00580 }
00581 }
00582
00583 #endif // ZYPP_TARGET_RPM_RPMDB_H