libzypp  15.28.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,
436  CHK_ERROR = 5,
437  CHK_NOSIG = 6,
438  };
439 
444  struct CheckPackageDetail : std::vector<std::pair<CheckPackageResult,std::string>>
445  {};
446 
457  CheckPackageResult checkPackage( const Pathname & path_r, CheckPackageDetail & detail_r );
459  CheckPackageResult checkPackage( const Pathname & path_r );
460 
471  CheckPackageResult checkPackageSignature( const Pathname & path_r, CheckPackageDetail & detail_r );
472 
483  void installPackage ( const Pathname & filename, RpmInstFlags flags = RPMINST_NONE );
484 
495  void removePackage( const std::string & name_r, RpmInstFlags flags = RPMINST_NONE );
496  void removePackage( Package::constPtr package, RpmInstFlags flags = RPMINST_NONE );
497 
502  Pathname getBackupPath (void)
503  {
504  return _backuppath;
505  }
506 
514  bool backupPackage(const std::string& packageName);
515 
522  bool backupPackage(const Pathname& filename);
523 
529  void setBackupPath(const Pathname& path);
530 
537  void createPackageBackups(bool yes)
538  {
539  _packagebackups = yes;
540  }
541 
552  bool queryChangedFiles(FileList & fileList, const std::string& packageName);
553 
554 public:
555 
559  virtual std::ostream & dumpOn( std::ostream & str ) const;
560 
561 protected:
562  void doRemovePackage( const std::string & name_r, RpmInstFlags flags, callback::SendReport<RpmRemoveReport> & report );
563  void doInstallPackage( const Pathname & filename, RpmInstFlags flags, callback::SendReport<RpmInstallReport> & report );
565 };
566 
568 std::ostream & operator<<( std::ostream & str, RpmDb::CheckPackageResult obj );
569 
571 std::ostream & operator<<( std::ostream & str, const RpmDb::CheckPackageDetail & obj );
572 
573 } // namespace rpm
574 } // namespace target
575 } // namespace zypp
576 
577 #endif // ZYPP_TARGET_RPM_RPMDB_H
std::ostream & operator<<(std::ostream &str, const librpmDb::DbDirInfo &obj)
Definition: librpmDb.cc:544
Interface to the rpm program.
Definition: RpmDb.h:47
CheckPackageResult checkPackageSignature(const Pathname &path_r, CheckPackageDetail &detail_r)
Check signature of rpm file on disk (strict check returning CHK_NOSIG if file is unsigned).
Definition: RpmDb.cc:1607
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:64
bool hasPackage(const std::string &name_r) const
Return true if package is installed.
Definition: RpmDb.cc:1394
bool hasProvides(const std::string &tag_r) const
Return true if at least one package provides a certain tag.
Definition: RpmDb.cc:1352
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.
Definition: RpmDb.cc:1422
void exportTrustedKeysInZyppKeyRing()
insert all rpm trusted keys into zypp trusted keyring
Definition: RpmDb.cc:1027
void rebuildDatabase()
Rebuild the rpm database (rpm –rebuilddb).
Definition: RpmDb.cc:777
void installPackage(const Pathname &filename, RpmInstFlags flags=RPMINST_NONE)
install rpm package
Definition: RpmDb.cc:1926
void internal_initDatabase(const Pathname &root_r, const Pathname &dbPath_r, DbStateInfoBits &info_r)
Internal helper for initDatabase.
Definition: RpmDb.cc:450
void modifyDatabase()
Called before the database is modified by installPackage/removePackage.
Definition: RpmDb.cc:707
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:1380
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:1024
~RpmDb()
Destructor.
Definition: RpmDb.cc:269
bool backupPackage(const std::string &packageName)
create tar.gz of all changed files in a Package
Definition: RpmDb.cc:2260
CheckPackageResult checkPackage(const Pathname &path_r, CheckPackageDetail &detail_r)
Check signature of rpm file on disk (legacy version returning CHK_OK if file is unsigned, like 'rpm -K')
Definition: RpmDb.cc:1601
Pathname getBackupPath(void)
get backup dir for rpm config files
Definition: RpmDb.h:502
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:1279
void importPubkey(const PublicKey &pubkey_r)
Import ascii armored public key in file pubkey_r.
Definition: RpmDb.cc:1036
void systemKill()
Forcably kill the system process.
Definition: RpmDb.cc:1822
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:965
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
virtual std::ostream & dumpOn(std::ostream &str) const
Dump debug info.
Definition: RpmDb.cc:301
Store and operate on date (time_t).
Definition: Date.h:32
Pathname _backuppath
/var/adm/backup
Definition: RpmDb.h:397
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:1725
int systemStatus()
Return the exit status of the general rpm process, closing the connection if not already done...
Definition: RpmDb.cc:1799
Detailed rpm signature check log messages A single multiline message if CHK_OK.
Definition: RpmDb.h:444
ExternalProgram * process
The connection to the rpm process.
Definition: RpmDb.h:351
RpmDb()
Constructor.
Definition: RpmDb.cc:247
void doRebuildDatabase(callback::SendReport< RebuildDBReport > &report)
Definition: RpmDb.cc:795
std::set< Edition > pubkeyEditions() const
Return the edition of all installed public keys.
Definition: RpmDb.cc:1255
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:730
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.
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:1956
void removePubkey(const PublicKey &pubkey_r)
Remove a public key from the rpm database.
Definition: RpmDb.cc:1146
void processConfigFiles(const std::string &line, const std::string &name, const char *typemsg, const char *difffailmsg, const char *diffgenmsg)
handle rpm messages like "/etc/testrc saved as /etc/testrc.rpmorig"
Definition: RpmDb.cc:1829
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:1366
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:277
void createPackageBackups(bool yes)
whether to create package backups during install or removal
Definition: RpmDb.h:537
bool _warndirexists
whether <_root>/<WARNINGMAILPATH> was already created
Definition: RpmDb.h:403
void doRemovePackage(const std::string &name_r, RpmInstFlags flags, callback::SendReport< RpmRemoveReport > &report)
Definition: RpmDb.cc:2145
void setBackupPath(const Pathname &path)
set path where package backups are stored
Definition: RpmDb.cc:2387
callback::SendReport< DownloadProgressReport > * report
Definition: MediaCurl.cc:184
void initDatabase(Pathname root_r=Pathname(), Pathname dbPath_r=Pathname(), bool doRebuild_r=false)
Prepare access to the rpm database.
Definition: RpmDb.cc:332
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
Definition: RpmDb.cc:2114
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:1308
Date timestamp() const
timestamp of the rpm database (last modification)
Definition: RpmDb.cc:278
const Pathname & dbPath() const
Definition: RpmDb.h:159
CheckPackageResult
checkPackage result
Definition: RpmDb.h:429
std::list< PublicKey > pubkeys() const
Return the long ids of all installed public keys.
Definition: RpmDb.cc:1217
void dbsi_set(DbStateInfoBits &val_r, const unsigned &bits_r) const
Definition: RpmDb.h:75
static void removeV3(const Pathname &dbdir_r, bool v3backup_r)
Remove the rpm3 database in dbdir_r.
Definition: RpmDb.cc:641
bool queryChangedFiles(FileList &fileList, const std::string &packageName)
determine which files of an installed package have been modified.
Definition: RpmDb.cc:1613
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:575
bool initialized() const
Definition: RpmDb.h:167
friend std::ostream & operator<<(std::ostream &str, const DbStateInfoBits &obj)
Definition: RpmDb.cc:206
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:1679
class InstTargetError Error
Default error class.
Definition: RpmDb.h:54
TraitsType::constPtrType constPtr
Definition: Package.h:38
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:1334
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