libzypp  17.24.1
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 #if LEGACY(1712)
63  enum DbStateInfoBits {
64  DbSI_NO_INIT = 0x0000
65  };
66  DbStateInfoBits _dbStateInfo;
67 #endif
68 
73 
78 
79 public:
80 
85  RpmDb();
86 
90  ~RpmDb();
91 
95  const Pathname & root() const
96  {
97  return _root;
98  }
99 
103  const Pathname & dbPath() const
104  {
105  return _dbPath;
106  }
107 
111  bool initialized() const
112  {
113  return( ! _root.empty() );
114  }
115 
130  void initDatabase( Pathname root_r = Pathname(), bool doRebuild_r = false );
131 
140  void closeDatabase();
141 
148  void rebuildDatabase();
149 
156  void importPubkey( const PublicKey & pubkey_r );
157 
164  void removePubkey( const PublicKey & pubkey_r );
165 
169  std::list<PublicKey> pubkeys() const;
170 
174  std::set<Edition> pubkeyEditions() const;
175 
177  //
178  // Direct RPM database retrieval via librpm.
179  //
181 public:
182 
188  std::list<FileInfo> fileList( const std::string & name_r, const Edition & edition_r ) const;
189 
194  bool hasFile( const std::string & file_r, const std::string & name_r = "" ) const;
195 
200  std::string whoOwnsFile( const std::string & file_r ) const;
201 
205  bool hasProvides( const std::string & tag_r ) const;
206 
210  bool hasRequiredBy( const std::string & tag_r ) const;
211 
215  bool hasConflicts( const std::string & tag_r ) const;
216 
220  bool hasPackage( const std::string & name_r ) const;
221 
225  bool hasPackage( const std::string & name_r, const Edition & ed_r ) const;
226 
238  void getData( const std::string & name_r,
239  RpmHeader::constPtr & result_r ) const;
240 
250  void getData( const std::string & name_r, const Edition & ed_r,
251  RpmHeader::constPtr & result_r ) const;
252 
254  //
256 public:
259  {
263  };
277 
278 private:
283 
284  typedef std::vector<const char*> RpmArgVec;
285 
295  void run_rpm( const RpmArgVec& options,
298 
299 
303  bool systemReadLine(std::string &line);
304 
309  int systemStatus();
310 
314  void systemKill();
315 
320 
325  std::string error_message;
326 
329 
332 
333 #if LEGACY(1712)
334 
335  bool _warndirexists;
336 #endif
337 
346  void processConfigFiles(const std::string& line,
347  const std::string& name,
348  const char* typemsg,
349  const char* difffailmsg,
350  const char* diffgenmsg);
351 
352 
353 public:
354 
355  typedef std::set<std::string> FileList;
356 
362  {
363  CHK_OK = 0,
365  CHK_FAIL = 2,
367  CHK_NOKEY = 4,
368  CHK_ERROR = 5,
369  CHK_NOSIG = 6,
370  };
371 
376  struct CheckPackageDetail : std::vector<std::pair<CheckPackageResult,std::string>>
377  {};
378 
389  CheckPackageResult checkPackage( const Pathname & path_r, CheckPackageDetail & detail_r );
391  CheckPackageResult checkPackage( const Pathname & path_r );
392 
404 
415  void installPackage ( const Pathname & filename, RpmInstFlags flags = RPMINST_NONE );
416 
427  void removePackage( const std::string & name_r, RpmInstFlags flags = RPMINST_NONE );
428  void removePackage( Package::constPtr package, RpmInstFlags flags = RPMINST_NONE );
429 
435  {
436  return _backuppath;
437  }
438 
446  bool backupPackage(const std::string& packageName);
447 
454  bool backupPackage(const Pathname& filename);
455 
461  void setBackupPath(const Pathname& path);
462 
469  void createPackageBackups(bool yes)
470  {
471  _packagebackups = yes;
472  }
473 
484  bool queryChangedFiles(FileList & fileList, const std::string& packageName);
485 
486 public:
487 
491  virtual std::ostream & dumpOn( std::ostream & str ) const;
492 
493 protected:
494  void doRemovePackage( const std::string & name_r, RpmInstFlags flags, callback::SendReport<RpmRemoveReport> & report );
495  void doInstallPackage( const Pathname & filename, RpmInstFlags flags, callback::SendReport<RpmInstallReport> & report );
497 };
498 
500 std::ostream & operator<<( std::ostream & str, RpmDb::CheckPackageResult obj );
501 
503 std::ostream & operator<<( std::ostream & str, const RpmDb::CheckPackageDetail & obj );
504 
505 } // namespace rpm
506 } // namespace target
507 } // namespace zypp
508 
509 #endif // ZYPP_TARGET_RPM_RPMDB_H
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:1273
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:64
bool hasRequiredBy(const std::string &tag_r) const
Return true if at least one package requires a certain tag.
Definition: RpmDb.cc:1027
void getData(const std::string &name_r, RpmHeader::constPtr &result_r) const
Get an installed packages data from rpmdb.
Definition: RpmDb.cc:1083
Pathname _root
Root directory for all operations.
Definition: RpmDb.h:72
void exportTrustedKeysInZyppKeyRing()
insert all rpm trusted keys into zypp trusted keyring
Definition: RpmDb.cc:689
void rebuildDatabase()
Rebuild the rpm database (rpm –rebuilddb).
Definition: RpmDb.cc:386
void installPackage(const Pathname &filename, RpmInstFlags flags=RPMINST_NONE)
install rpm package
Definition: RpmDb.cc:1597
std::ostream & operator<<(std::ostream &str, const librpmDb::db_const_iterator &obj)
Definition: librpmDb.cc:695
String related utilities and Regular expression matching.
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
void importZyppKeyRingTrustedKeys()
iterates through zypp keyring and import all non existant keys into rpm keyring
Definition: RpmDb.cc:686
~RpmDb()
Destructor.
Definition: RpmDb.cc:237
bool backupPackage(const std::string &packageName)
create tar.gz of all changed files in a Package
Definition: RpmDb.cc:1948
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 &#39;rpm -K&#39;)
Definition: RpmDb.cc:1267
Pathname getBackupPath(void)
get backup dir for rpm config files
Definition: RpmDb.h:434
void importPubkey(const PublicKey &pubkey_r)
Import ascii armored public key in file pubkey_r.
Definition: RpmDb.cc:698
bool hasPackage(const std::string &name_r) const
Return true if package is installed.
Definition: RpmDb.cc:1055
void systemKill()
Forcably kill the system process.
Definition: RpmDb.cc:1493
bool empty() const
Test for an empty path.
Definition: Pathname.h:114
void syncTrustedKeys(SyncTrustedKeyBits mode_r=SYNC_BOTH)
Sync trusted keys stored in rpm database and zypp trusted keyring.
Definition: RpmDb.cc:585
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
Pathname _backuppath
/var/adm/backup
Definition: RpmDb.h:328
int exit_code
The exit code of the rpm process, or -1 if not yet known.
Definition: RpmDb.h:319
std::list< PublicKey > pubkeys() const
Return the long ids of all installed public keys.
Definition: RpmDb.cc:878
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:258
bool systemReadLine(std::string &line)
Read a line from the general rpm query.
Definition: RpmDb.cc:1392
int systemStatus()
Return the exit status of the general rpm process, closing the connection if not already done...
Definition: RpmDb.cc:1470
std::set< Edition > pubkeyEditions() const
Return the edition of all installed public keys.
Definition: RpmDb.cc:916
Detailed rpm signature check log messages A single multiline message if CHK_OK.
Definition: RpmDb.h:376
virtual std::ostream & dumpOn(std::ostream &str) const
Dump debug info.
Definition: RpmDb.cc:252
ExternalProgram * process
The connection to the rpm process.
Definition: RpmDb.h:282
RpmDb()
Constructor.
Definition: RpmDb.cc:218
void doRebuildDatabase(callback::SendReport< RebuildDBReport > &report)
Definition: RpmDb.cc:404
void initDatabase(Pathname root_r=Pathname(), bool doRebuild_r=false)
Prepare access to the rpm database at /var/lib/rpm.
Definition: RpmDb.cc:263
void closeDatabase()
Block further access to the rpm database and go back to uninitialized state.
Definition: RpmDb.cc:358
Stderr_Disposition
Define symbols for different policies on the handling of stderr.
Base class for reference counted objects.
bool hasProvides(const std::string &tag_r) const
Return true if at least one package provides a certain tag.
Definition: RpmDb.cc:1013
import zypp trusted keys into rpm database.
Definition: RpmDb.h:261
void doInstallPackage(const Pathname &filename, RpmInstFlags flags, callback::SendReport< RpmInstallReport > &report)
Definition: RpmDb.cc:1627
void removePubkey(const PublicKey &pubkey_r)
Remove a public key from the rpm database.
Definition: RpmDb.cc:811
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:1500
bool _packagebackups
create package backups?
Definition: RpmDb.h:331
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:275
void createPackageBackups(bool yes)
whether to create package backups during install or removal
Definition: RpmDb.h:469
void doRemovePackage(const std::string &name_r, RpmInstFlags flags, callback::SendReport< RpmRemoveReport > &report)
Definition: RpmDb.cc:1823
void setBackupPath(const Pathname &path)
set path where package backups are stored
Definition: RpmDb.cc:2075
const Pathname & root() const
Definition: RpmDb.h:95
bool hasConflicts(const std::string &tag_r) const
Return true if at least one package conflicts with a certain tag.
Definition: RpmDb.cc:1041
const Pathname & dbPath() const
Definition: RpmDb.h:103
callback::SendReport< DownloadProgressReport > * report
Definition: MediaCurl.cc:70
std::string error_message
Error message from running rpm as external program.
Definition: RpmDb.h:325
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:995
void removePackage(const std::string &name_r, RpmInstFlags flags=RPMINST_NONE)
remove rpm package
Definition: RpmDb.cc:1792
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:940
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:969
CheckPackageResult
checkPackage result
Definition: RpmDb.h:361
bool queryChangedFiles(FileList &fileList, const std::string &packageName)
determine which files of an installed package have been modified.
Definition: RpmDb.cc:1279
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
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:1345
export rpm trusted keys into zypp trusted keyring
Definition: RpmDb.h:260
bool initialized() const
Definition: RpmDb.h:111
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:77
std::set< std::string > FileList
Definition: RpmDb.h:355
std::vector< const char * > RpmArgVec
Definition: RpmDb.h:284