libzypp  13.10.6
RpmDb.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
13 // -*- C++ -*-
14 
15 #ifndef ZYPP_TARGET_RPM_RPMDB_H
16 #define ZYPP_TARGET_RPM_RPMDB_H
17 
18 #include <iosfwd>
19 #include <list>
20 #include <vector>
21 #include <string>
22 
23 #include "zypp/Pathname.h"
24 #include "zypp/ExternalProgram.h"
25 
26 #include "zypp/Package.h"
27 #include "zypp/KeyRing.h"
28 
32 #include "zypp/ZYppCallbacks.h"
33 
34 namespace zypp
35 {
36 namespace target
37 {
38 namespace rpm
39 {
40 
42 //
43 // CLASS NAME : RpmDb
48 {
49 public:
50 
54  typedef class InstTargetError Error;
55 
57  //
58  // INITALISATION
59  //
61 private:
62 
64  DbSI_NO_INIT = 0x0000,
65  DbSI_HAVE_V4 = 0x0001,
66  DbSI_MADE_V4 = 0x0002,
67  DbSI_MODIFIED_V4 = 0x0004,
68  DbSI_HAVE_V3 = 0x0008,
69  DbSI_HAVE_V3TOV4 = 0x0010,
71  };
72 
73  friend std::ostream & operator<<( std::ostream & str, const DbStateInfoBits & obj );
74 
75  void dbsi_set( DbStateInfoBits & val_r, const unsigned & bits_r ) const
76  {
77  val_r = (DbStateInfoBits)(val_r | bits_r);
78  }
79  void dbsi_clr( DbStateInfoBits & val_r, const unsigned & bits_r ) const
80  {
81  val_r = (DbStateInfoBits)(val_r & ~bits_r);
82  }
83  bool dbsi_has( const DbStateInfoBits & val_r, const unsigned & bits_r ) const
84  {
85  return( (val_r & bits_r) == bits_r );
86  }
87 
92 
96  Pathname _root;
97 
101  Pathname _dbPath;
102 
109  void internal_initDatabase( const Pathname & root_r, const Pathname & dbPath_r,
110  DbStateInfoBits & info_r );
111 
116  static void removeV4( const Pathname & dbdir_r, bool v3backup_r );
117 
122  static void removeV3( const Pathname & dbdir_r, bool v3backup_r );
123 
128  void modifyDatabase();
129 
130 public:
131 
136  RpmDb();
137 
141  ~RpmDb();
142 
146  Date timestamp() const;
147 
151  const Pathname & root() const
152  {
153  return _root;
154  }
155 
159  const Pathname & dbPath() const
160  {
161  return _dbPath;
162  }
163 
167  bool initialized() const
168  {
169  return( ! _root.empty() );
170  }
171 
197  void initDatabase( Pathname root_r = Pathname(),
198  Pathname dbPath_r = Pathname(),
199  bool doRebuild_r = false );
200 
209  void closeDatabase();
210 
217  void rebuildDatabase();
218 
225  void importPubkey( const PublicKey & pubkey_r );
226 
233  void removePubkey( const PublicKey & pubkey_r );
234 
238  std::list<PublicKey> pubkeys() const;
239 
243  std::set<Edition> pubkeyEditions() const;
244 
246  //
247  // Direct RPM database retrieval via librpm.
248  //
250 public:
251 
257  std::list<FileInfo> fileList( const std::string & name_r, const Edition & edition_r ) const;
258 
263  bool hasFile( const std::string & file_r, const std::string & name_r = "" ) const;
264 
269  std::string whoOwnsFile( const std::string & file_r ) const;
270 
274  bool hasProvides( const std::string & tag_r ) const;
275 
279  bool hasRequiredBy( const std::string & tag_r ) const;
280 
284  bool hasConflicts( const std::string & tag_r ) const;
285 
289  bool hasPackage( const std::string & name_r ) const;
290 
294  bool hasPackage( const std::string & name_r, const Edition & ed_r ) const;
295 
307  void getData( const std::string & name_r,
308  RpmHeader::constPtr & result_r ) const;
309 
319  void getData( const std::string & name_r, const Edition & ed_r,
320  RpmHeader::constPtr & result_r ) const;
321 
323  //
325 public:
328  {
332  };
346 
347 private:
352 
353  typedef std::vector<const char*> RpmArgVec;
354 
364  void run_rpm( const RpmArgVec& options,
367 
368 
372  bool systemReadLine(std::string &line);
373 
378  int systemStatus();
379 
383  void systemKill();
384 
389 
394  std::string error_message;
395 
397  Pathname _backuppath;
398 
401 
404 
414  void processConfigFiles(const std::string& line,
415  const std::string& name,
416  const char* typemsg,
417  const char* difffailmsg,
418  const char* diffgenmsg);
419 
420 
421 public:
422 
423  typedef std::set<std::string> FileList;
424 
430  {
431  CHK_OK = 0,
433  CHK_FAIL = 2,
435  CHK_NOKEY = 4,
437  };
438 
446  checkPackageResult checkPackage( const Pathname & path_r );
447 
458  void installPackage ( const Pathname & filename, RpmInstFlags flags = RPMINST_NONE );
459 
470  void removePackage( const std::string & name_r, RpmInstFlags flags = RPMINST_NONE );
471  void removePackage( Package::constPtr package, RpmInstFlags flags = RPMINST_NONE );
472 
477  Pathname getBackupPath (void)
478  {
479  return _backuppath;
480  }
481 
489  bool backupPackage(const std::string& packageName);
490 
497  bool backupPackage(const Pathname& filename);
498 
504  void setBackupPath(const Pathname& path);
505 
512  void createPackageBackups(bool yes)
513  {
514  _packagebackups = yes;
515  }
516 
527  bool queryChangedFiles(FileList & fileList, const std::string& packageName);
528 
529 public:
530 
534  virtual std::ostream & dumpOn( std::ostream & str ) const;
535 
536 protected:
537  void doRemovePackage( const std::string & name_r, RpmInstFlags flags, callback::SendReport<RpmRemoveReport> & report );
538  void doInstallPackage( const Pathname & filename, RpmInstFlags flags, callback::SendReport<RpmInstallReport> & report );
540 };
541 
542 } // namespace rpm
543 } // namespace target
544 } // namespace zypp
545 
546 #endif // ZYPP_TARGET_RPM_RPMDB_H
Interface to the rpm program.
Definition: RpmDb.h:47
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:65
bool hasPackage(const std::string &name_r) const
Return true if package is installed.
bool hasProvides(const std::string &tag_r) const
Return true if at least one package provides a certain tag.
Definition: RpmDb.cc:1344
Pathname _root
Root directory for all operations.
Definition: RpmDb.h:96
void getData(const std::string &name_r, RpmHeader::constPtr &result_r) const
Get an installed packages data from rpmdb.
void exportTrustedKeysInZyppKeyRing()
insert all rpm trusted keys into zypp trusted keyring
Definition: RpmDb.cc:1025
void rebuildDatabase()
Rebuild the rpm database (rpm –rebuilddb).
Definition: RpmDb.cc:774
void installPackage(const Pathname &filename, RpmInstFlags flags=RPMINST_NONE)
install rpm package
Definition: RpmDb.cc:1814
void internal_initDatabase(const Pathname &root_r, const Pathname &dbPath_r, DbStateInfoBits &info_r)
Internal helper for initDatabase.
Definition: RpmDb.cc:447
void modifyDatabase()
Called before the database is modified by installPackage/removePackage.
Definition: RpmDb.cc:704
virtual std::ostream & dumpOn(std::ostream &str) const
Dump debug info.
Definition: RpmDb.cc:298
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
bool hasConflicts(const std::string &tag_r) const
Return true if at least one package conflicts with a certain tag.
Definition: RpmDb.cc:1372
import zypp trusted keys into rpm database.
Definition: RpmDb.h:331
void importZyppKeyRingTrustedKeys()
iterates through zypp keyring and import all non existant keys into rpm keyring
Definition: RpmDb.cc:1022
~RpmDb()
Destructor.
Definition: RpmDb.cc:266
bool backupPackage(const std::string &packageName)
create tar.gz of all changed files in a Package
Pathname getBackupPath(void)
get backup dir for rpm config files
Definition: RpmDb.h:477
void importPubkey(const PublicKey &pubkey_r)
Import ascii armored public key in file pubkey_r.
Definition: RpmDb.cc:1034
void systemKill()
Forcably kill the system process.
Definition: RpmDb.cc:1710
bool dbsi_has(const DbStateInfoBits &val_r, const unsigned &bits_r) const
Definition: RpmDb.h:83
void syncTrustedKeys(SyncTrustedKeyBits mode_r=SYNC_BOTH)
Sync trusted keys stored in rpm database and zypp trusted keyring.
Definition: RpmDb.cc:963
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
Store and operate on date (time_t).
Definition: Date.h:31
Pathname _backuppath
/var/adm/backup
Definition: RpmDb.h:397
std::list< FileInfo > fileList(const std::string &name_r, const Edition &edition_r) const
return complete file list for installed package name_r (in FileInfo.filename) if edition_r != Edition...
Definition: RpmDb.cc:1271
int exit_code
The exit code of the rpm process, or -1 if not yet known.
Definition: RpmDb.h:388
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
SyncTrustedKeyBits
Sync mode for syncTrustedKeys.
Definition: RpmDb.h:327
bool systemReadLine(std::string &line)
Read a line from the general rpm query.
Definition: RpmDb.cc:1613
int systemStatus()
Return the exit status of the general rpm process, closing the connection if not already done...
Definition: RpmDb.cc:1687
ExternalProgram * process
The connection to the rpm process.
Definition: RpmDb.h:351
RpmDb()
Constructor.
Definition: RpmDb.cc:244
void doRebuildDatabase(callback::SendReport< RebuildDBReport > &report)
Definition: RpmDb.cc:792
const Pathname & root() const
Definition: RpmDb.h:151
void closeDatabase()
Block further access to the rpm database and go back to uninitialized state.
Definition: RpmDb.cc:727
Stderr_Disposition
Define symbols for different policies on the handling of stderr.
DbStateInfoBits _dbStateInfo
Internal state info.
Definition: RpmDb.h:91
Base class for reference counted objects.
checkPackageResult checkPackage(const Pathname &path_r)
Check signature of rpm file on disk.
Definition: RpmDb.cc:1447
export rpm trusted keys into zypp trusted keyring
Definition: RpmDb.h:330
void doInstallPackage(const Pathname &filename, RpmInstFlags flags, callback::SendReport< RpmInstallReport > &report)
Definition: RpmDb.cc:1844
std::set< Edition > pubkeyEditions() const
Return the edition of all installed public keys.
Definition: RpmDb.cc:1247
void removePubkey(const PublicKey &pubkey_r)
Remove a public key from the rpm database.
Definition: RpmDb.cc:1138
void processConfigFiles(const std::string &line, const std::string &name, const char *typemsg, const char *difffailmsg, const char *diffgenmsg)
handle rpm messages like &quot;/etc/testrc saved as /etc/testrc.rpmorig&quot;
Definition: RpmDb.cc:1717
bool _packagebackups
create package backups?
Definition: RpmDb.h:400
bool hasRequiredBy(const std::string &tag_r) const
Return true if at least one package requires a certain tag.
Definition: RpmDb.cc:1358
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:208
void createPackageBackups(bool yes)
whether to create package backups during install or removal
Definition: RpmDb.h:512
bool _warndirexists
whether &lt;_root&gt;/&lt;WARNINGMAILPATH&gt; was already created
Definition: RpmDb.h:403
void doRemovePackage(const std::string &name_r, RpmInstFlags flags, callback::SendReport< RpmRemoveReport > &report)
Definition: RpmDb.cc:2031
void setBackupPath(const Pathname &path)
set path where package backups are stored
Definition: RpmDb.cc:2274
callback::SendReport< DownloadProgressReport > * report
Definition: MediaCurl.cc:178
void initDatabase(Pathname root_r=Pathname(), Pathname dbPath_r=Pathname(), bool doRebuild_r=false)
Prepare access to the rpm database.
Definition: RpmDb.cc:329
std::string error_message
Error message from running rpm as external program.
Definition: RpmDb.h:394
void removePackage(const std::string &name_r, RpmInstFlags flags=RPMINST_NONE)
remove rpm package
std::list< PublicKey > pubkeys() const
Return the long ids of all installed public keys.
Definition: RpmDb.cc:1209
bool hasFile(const std::string &file_r, const std::string &name_r="") const
Return true if at least one package owns a certain file (name_r empty) Return true if package name_r ...
Definition: RpmDb.cc:1300
Date timestamp() const
timestamp of the rpm database (last modification)
Definition: RpmDb.cc:275
const Pathname & dbPath() const
Definition: RpmDb.h:159
void dbsi_set(DbStateInfoBits &val_r, const unsigned &bits_r) const
Definition: RpmDb.h:75
std::string whoOwnsFile(const std::string &file_r) const
Return name of package owning file or empty string if no installed package owns file.
Definition: RpmDb.cc:1326
checkPackageResult
checkPackage result
Definition: RpmDb.h:429
static void removeV3(const Pathname &dbdir_r, bool v3backup_r)
Remove the rpm3 database in dbdir_r.
Definition: RpmDb.cc:638
bool queryChangedFiles(FileList &fileList, const std::string &packageName)
determine which files of an installed package have been modified.
Definition: RpmDb.cc:1501
void dbsi_clr(DbStateInfoBits &val_r, const unsigned &bits_r) const
Definition: RpmDb.h:79
static void removeV4(const Pathname &dbdir_r, bool v3backup_r)
Remove the rpm4 database in dbdir_r and optionally any backup created on conversion.
Definition: RpmDb.cc:572
bool initialized() const
Definition: RpmDb.h:167
friend std::ostream & operator<<(std::ostream &str, const DbStateInfoBits &obj)
void run_rpm(const RpmArgVec &options, ExternalProgram::Stderr_Disposition stderr_disp=ExternalProgram::Stderr_To_Stdout)
Run rpm with the specified arguments and handle stderr.
Definition: RpmDb.cc:1567
class InstTargetError Error
Default error class.
Definition: RpmDb.h:54
TraitsType::constPtrType constPtr
Definition: Package.h:38
Pathname _dbPath
Directory that contains the rpmdb.
Definition: RpmDb.h:101
std::set< std::string > FileList
Definition: RpmDb.h:423
std::vector< const char * > RpmArgVec
Definition: RpmDb.h:353