libzypp  17.31.31
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 #include <functional>
23 
24 #include <zypp/Pathname.h>
25 #include <zypp/ExternalProgram.h>
26 
27 #include <zypp/Package.h>
28 #include <zypp/KeyRing.h>
29 
33 #include <zypp/ZYppCallbacks.h>
34 
35 namespace zypp
36 {
37 namespace target
38 {
39 class RpmPostTransCollector;
40 namespace rpm
41 {
42 
44 //
45 // CLASS NAME : RpmDb
50 {
51 public:
52 
56  typedef class InstTargetError Error;
57 
59  //
60  // INITALISATION
61  //
63 private:
64 
69 
74 
75 public:
76 
81  RpmDb();
82 
86  ~RpmDb();
87 
91  const Pathname & root() const
92  {
93  return _root;
94  }
95 
99  const Pathname & dbPath() const
100  {
101  return _dbPath;
102  }
103 
107  bool initialized() const
108  {
109  return( ! _root.empty() );
110  }
111 
126  void initDatabase( Pathname root_r = Pathname(), bool doRebuild_r = false );
127 
136  void closeDatabase();
137 
144  void rebuildDatabase();
145 
152  void importPubkey( const PublicKey & pubkey_r );
153 
160  void removePubkey( const PublicKey & pubkey_r );
161 
165  std::list<PublicKey> pubkeys() const;
166 
170  std::set<Edition> pubkeyEditions() const;
171 
173  //
174  // Direct RPM database retrieval via librpm.
175  //
177 public:
178 
184  std::list<FileInfo> fileList( const std::string & name_r, const Edition & edition_r ) const;
185 
190  bool hasFile( const std::string & file_r, const std::string & name_r = "" ) const;
191 
196  std::string whoOwnsFile( const std::string & file_r ) const;
197 
201  bool hasProvides( const std::string & tag_r ) const;
202 
206  bool hasRequiredBy( const std::string & tag_r ) const;
207 
211  bool hasConflicts( const std::string & tag_r ) const;
212 
216  bool hasPackage( const std::string & name_r ) const;
217 
221  bool hasPackage( const std::string & name_r, const Edition & ed_r ) const;
222 
234  void getData( const std::string & name_r,
235  RpmHeader::constPtr & result_r ) const;
236 
246  void getData( const std::string & name_r, const Edition & ed_r,
247  RpmHeader::constPtr & result_r ) const;
248 
250  //
252 public:
255  {
259  };
273 
274 private:
279 
280  typedef std::vector<const char*> RpmArgVec;
281 
291  void run_rpm( const RpmArgVec& options,
294 
295 
299  bool systemReadLine(std::string &line);
300 
305  int systemStatus();
306 
310  void systemKill();
311 
316 
321  std::string error_message;
322 
325 
328 
338  void processConfigFiles(const std::string& line,
339  const std::string& name,
340  const char* typemsg,
341  const char* difffailmsg,
342  const char* diffgenmsg);
343 
344 
345 public:
346 
347  typedef std::set<std::string> FileList;
348 
354  {
355  CHK_OK = 0,
357  CHK_FAIL = 2,
359  CHK_NOKEY = 4,
360  CHK_ERROR = 5,
361  CHK_NOSIG = 6,
362  };
363 
368  struct CheckPackageDetail : std::vector<std::pair<CheckPackageResult,std::string>>
369  {};
370 
381  CheckPackageResult checkPackage( const Pathname & path_r, CheckPackageDetail & detail_r );
383  CheckPackageResult checkPackage( const Pathname & path_r );
384 
396 
407  void installPackage ( const Pathname & filename, RpmInstFlags flags = RPMINST_NONE );
409  void installPackage( const Pathname & filename, RpmInstFlags flags, RpmPostTransCollector* postTransCollector_r );
410 
421  void removePackage( const std::string & name_r, RpmInstFlags flags = RPMINST_NONE );
422  void removePackage( Package::constPtr package, RpmInstFlags flags = RPMINST_NONE );
424  void removePackage( const std::string & name_r, RpmInstFlags flags, RpmPostTransCollector* postTransCollector_r );
425  void removePackage( Package::constPtr package, RpmInstFlags flags, RpmPostTransCollector* postTransCollector_r );
426 
431  int runposttrans( const Pathname & filename_r, std::function<void(const std::string&)> output_r );
432 
438  {
439  return _backuppath;
440  }
441 
449  bool backupPackage(const std::string& packageName);
450 
457  bool backupPackage(const Pathname& filename);
458 
464  void setBackupPath(const Pathname& path);
465 
472  void createPackageBackups(bool yes)
473  {
474  _packagebackups = yes;
475  }
476 
487  bool queryChangedFiles(FileList & fileList, const std::string& packageName);
488 
489 public:
490 
494  virtual std::ostream & dumpOn( std::ostream & str ) const;
495 
496 protected:
497  void doRemovePackage( const std::string & name_r, RpmInstFlags flags, RpmPostTransCollector* postTransCollector_r, callback::SendReport<RpmRemoveReport> & report );
498  void doInstallPackage( const Pathname & filename, RpmInstFlags flags, RpmPostTransCollector* postTransCollector_r, callback::SendReport<RpmInstallReport> & report );
500 };
501 
503 std::ostream & operator<<( std::ostream & str, RpmDb::CheckPackageResult obj );
504 
506 std::ostream & operator<<( std::ostream & str, const RpmDb::CheckPackageDetail & obj );
507 
508 } // namespace rpm
509 } // namespace target
510 } // namespace zypp
511 
512 #endif // ZYPP_TARGET_RPM_RPMDB_H
Interface to the rpm program.
Definition: RpmDb.h:49
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:1362
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:65
bool hasRequiredBy(const std::string &tag_r) const
Return true if at least one package requires a certain tag.
Definition: RpmDb.cc:1030
void getData(const std::string &name_r, RpmHeader::constPtr &result_r) const
Get an installed packages data from rpmdb.
Definition: RpmDb.cc:1086
Pathname _root
Root directory for all operations.
Definition: RpmDb.h:68
void exportTrustedKeysInZyppKeyRing()
insert all rpm trusted keys into zypp trusted keyring
Definition: RpmDb.cc:692
void doInstallPackage(const Pathname &filename, RpmInstFlags flags, RpmPostTransCollector *postTransCollector_r, callback::SendReport< RpmInstallReport > &report)
Definition: RpmDb.cc:1694
void rebuildDatabase()
Rebuild the rpm database (rpm –rebuilddb).
Definition: RpmDb.cc:389
void installPackage(const Pathname &filename, RpmInstFlags flags=RPMINST_NONE)
install rpm package
Definition: RpmDb.cc:1658
std::ostream & operator<<(std::ostream &str, const librpmDb::db_const_iterator &obj)
Definition: librpmDb.cc:706
void doRemovePackage(const std::string &name_r, RpmInstFlags flags, RpmPostTransCollector *postTransCollector_r, callback::SendReport< RpmRemoveReport > &report)
Definition: RpmDb.cc:1905
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-existent keys into rpm keyring
Definition: RpmDb.cc:689
~RpmDb()
Destructor.
Definition: RpmDb.cc:245
bool backupPackage(const std::string &packageName)
create tar.gz of all changed files in a Package
Definition: RpmDb.cc:2107
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:1356
Pathname getBackupPath(void)
get backup dir for rpm config files
Definition: RpmDb.h:437
Extract and remember posttrans scripts for later execution.
void importPubkey(const PublicKey &pubkey_r)
Import ascii armored public key in file pubkey_r.
Definition: RpmDb.cc:701
bool hasPackage(const std::string &name_r) const
Return true if package is installed.
Definition: RpmDb.cc:1058
void systemKill()
Forcably kill the system process.
Definition: RpmDb.cc:1556
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:588
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
Pathname _backuppath
/var/adm/backup
Definition: RpmDb.h:324
int exit_code
The exit code of the rpm process, or -1 if not yet known.
Definition: RpmDb.h:315
std::list< PublicKey > pubkeys() const
Return the long ids of all installed public keys.
Definition: RpmDb.cc:881
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:254
bool systemReadLine(std::string &line)
Read a line from the general rpm query.
Definition: RpmDb.cc:1480
int systemStatus()
Return the exit status of the general rpm process, closing the connection if not already done...
Definition: RpmDb.cc:1533
std::set< Edition > pubkeyEditions() const
Return the edition of all installed public keys.
Definition: RpmDb.cc:919
Detailed rpm signature check log messages A single multiline message if CHK_OK.
Definition: RpmDb.h:368
virtual std::ostream & dumpOn(std::ostream &str) const
Dump debug info.
Definition: RpmDb.cc:260
ExternalProgram * process
The connection to the rpm process.
Definition: RpmDb.h:278
RpmDb()
Constructor.
Definition: RpmDb.cc:226
void doRebuildDatabase(callback::SendReport< RebuildDBReport > &report)
Definition: RpmDb.cc:407
void initDatabase(Pathname root_r=Pathname(), bool doRebuild_r=false)
Prepare access to the rpm database below root_r.
Definition: RpmDb.cc:271
void closeDatabase()
Block further access to the rpm database and go back to uninitialized state.
Definition: RpmDb.cc:361
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:1016
import zypp trusted keys into rpm database.
Definition: RpmDb.h:257
void removePubkey(const PublicKey &pubkey_r)
Remove a public key from the rpm database.
Definition: RpmDb.cc:814
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:1563
bool _packagebackups
create package backups?
Definition: RpmDb.h:327
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:358
void createPackageBackups(bool yes)
whether to create package backups during install or removal
Definition: RpmDb.h:472
void setBackupPath(const Pathname &path)
set path where package backups are stored
Definition: RpmDb.cc:2234
const Pathname & root() const
Definition: RpmDb.h:91
bool hasConflicts(const std::string &tag_r) const
Return true if at least one package conflicts with a certain tag.
Definition: RpmDb.cc:1044
const Pathname & dbPath() const
Definition: RpmDb.h:99
std::string error_message
Error message from running rpm as external program.
Definition: RpmDb.h:321
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:998
int runposttrans(const Pathname &filename_r, std::function< void(const std::string &)> output_r)
Run collected posttrans and transfiletrigger(postun|in) if rpm --runposttrans is supported.
Definition: RpmDb.cc:2034
void removePackage(const std::string &name_r, RpmInstFlags flags=RPMINST_NONE)
remove rpm package
Definition: RpmDb.cc:1864
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:943
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:972
CheckPackageResult
checkPackage result
Definition: RpmDb.h:353
bool queryChangedFiles(FileList &fileList, const std::string &packageName)
determine which files of an installed package have been modified.
Definition: RpmDb.cc:1368
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:1433
export rpm trusted keys into zypp trusted keyring
Definition: RpmDb.h:256
bool initialized() const
Definition: RpmDb.h:107
class InstTargetError Error
Default error class.
Definition: RpmDb.h:56
TraitsType::constPtrType constPtr
Definition: Package.h:38
Pathname _dbPath
Directory that contains the rpmdb.
Definition: RpmDb.h:73
std::set< std::string > FileList
Definition: RpmDb.h:347
std::vector< const char * > RpmArgVec
Definition: RpmDb.h:280