libzypp  17.25.2
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 
67 
72 
73 public:
74 
79  RpmDb();
80 
84  ~RpmDb();
85 
89  const Pathname & root() const
90  {
91  return _root;
92  }
93 
97  const Pathname & dbPath() const
98  {
99  return _dbPath;
100  }
101 
105  bool initialized() const
106  {
107  return( ! _root.empty() );
108  }
109 
124  void initDatabase( Pathname root_r = Pathname(), bool doRebuild_r = false );
125 
134  void closeDatabase();
135 
142  void rebuildDatabase();
143 
150  void importPubkey( const PublicKey & pubkey_r );
151 
158  void removePubkey( const PublicKey & pubkey_r );
159 
163  std::list<PublicKey> pubkeys() const;
164 
168  std::set<Edition> pubkeyEditions() const;
169 
171  //
172  // Direct RPM database retrieval via librpm.
173  //
175 public:
176 
182  std::list<FileInfo> fileList( const std::string & name_r, const Edition & edition_r ) const;
183 
188  bool hasFile( const std::string & file_r, const std::string & name_r = "" ) const;
189 
194  std::string whoOwnsFile( const std::string & file_r ) const;
195 
199  bool hasProvides( const std::string & tag_r ) const;
200 
204  bool hasRequiredBy( const std::string & tag_r ) const;
205 
209  bool hasConflicts( const std::string & tag_r ) const;
210 
214  bool hasPackage( const std::string & name_r ) const;
215 
219  bool hasPackage( const std::string & name_r, const Edition & ed_r ) const;
220 
232  void getData( const std::string & name_r,
233  RpmHeader::constPtr & result_r ) const;
234 
244  void getData( const std::string & name_r, const Edition & ed_r,
245  RpmHeader::constPtr & result_r ) const;
246 
248  //
250 public:
253  {
257  };
271 
272 private:
277 
278  typedef std::vector<const char*> RpmArgVec;
279 
289  void run_rpm( const RpmArgVec& options,
292 
293 
297  bool systemReadLine(std::string &line);
298 
303  int systemStatus();
304 
308  void systemKill();
309 
314 
319  std::string error_message;
320 
323 
326 
336  void processConfigFiles(const std::string& line,
337  const std::string& name,
338  const char* typemsg,
339  const char* difffailmsg,
340  const char* diffgenmsg);
341 
342 
343 public:
344 
345  typedef std::set<std::string> FileList;
346 
352  {
353  CHK_OK = 0,
355  CHK_FAIL = 2,
357  CHK_NOKEY = 4,
358  CHK_ERROR = 5,
359  CHK_NOSIG = 6,
360  };
361 
366  struct CheckPackageDetail : std::vector<std::pair<CheckPackageResult,std::string>>
367  {};
368 
379  CheckPackageResult checkPackage( const Pathname & path_r, CheckPackageDetail & detail_r );
381  CheckPackageResult checkPackage( const Pathname & path_r );
382 
394 
405  void installPackage ( const Pathname & filename, RpmInstFlags flags = RPMINST_NONE );
406 
417  void removePackage( const std::string & name_r, RpmInstFlags flags = RPMINST_NONE );
418  void removePackage( Package::constPtr package, RpmInstFlags flags = RPMINST_NONE );
419 
425  {
426  return _backuppath;
427  }
428 
436  bool backupPackage(const std::string& packageName);
437 
444  bool backupPackage(const Pathname& filename);
445 
451  void setBackupPath(const Pathname& path);
452 
459  void createPackageBackups(bool yes)
460  {
461  _packagebackups = yes;
462  }
463 
474  bool queryChangedFiles(FileList & fileList, const std::string& packageName);
475 
476 public:
477 
481  virtual std::ostream & dumpOn( std::ostream & str ) const;
482 
483 protected:
484  void doRemovePackage( const std::string & name_r, RpmInstFlags flags, callback::SendReport<RpmRemoveReport> & report );
485  void doInstallPackage( const Pathname & filename, RpmInstFlags flags, callback::SendReport<RpmInstallReport> & report );
487 };
488 
490 std::ostream & operator<<( std::ostream & str, RpmDb::CheckPackageResult obj );
491 
493 std::ostream & operator<<( std::ostream & str, const RpmDb::CheckPackageDetail & obj );
494 
495 } // namespace rpm
496 } // namespace target
497 } // namespace zypp
498 
499 #endif // ZYPP_TARGET_RPM_RPMDB_H
zypp::target::rpm::RpmDb::initialized
bool initialized() const
Definition: RpmDb.h:105
ExternalProgram.h
zypp::ExternalProgram::Stderr_To_Stdout
@ Stderr_To_Stdout
Definition: ExternalProgram.h:73
zypp::target::rpm::RpmDb::run_rpm
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:1348
zypp::target::rpm::RpmDb::removePubkey
void removePubkey(const PublicKey &pubkey_r)
Remove a public key from the rpm database.
Definition: RpmDb.cc:812
zypp::target::rpm::RpmDb::doRebuildDatabase
void doRebuildDatabase(callback::SendReport< RebuildDBReport > &report)
Definition: RpmDb.cc:405
zypp::target::rpm::RpmDb::CHK_NOSIG
@ CHK_NOSIG
Definition: RpmDb.h:359
zypp::target::rpm::RpmDb::CheckPackageResult
CheckPackageResult
checkPackage result
Definition: RpmDb.h:352
zypp::target::rpm::RpmDb::closeDatabase
void closeDatabase()
Block further access to the rpm database and go back to uninitialized state.
Definition: RpmDb.cc:359
zypp::callback::SendReport
Definition: Callback.h:237
zypp::target::rpm::RpmDb::pubkeyEditions
std::set< Edition > pubkeyEditions() const
Return the edition of all installed public keys.
Definition: RpmDb.cc:917
RpmHeader.h
zypp::target::rpm::RpmDb::_backuppath
Pathname _backuppath
/var/adm/backup
Definition: RpmDb.h:322
zypp::target::rpm::RpmDb::setBackupPath
void setBackupPath(const Pathname &path)
set path where package backups are stored
Definition: RpmDb.cc:2052
zypp::target::rpm::RpmDb::hasConflicts
bool hasConflicts(const std::string &tag_r) const
Return true if at least one package conflicts with a certain tag.
Definition: RpmDb.cc:1042
zypp::target::rpm::RpmDb::checkPackageSignature
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:1276
zypp::target::rpm::RpmDb::CHK_OK
@ CHK_OK
Definition: RpmDb.h:353
zypp::target::rpm::RpmDb::backupPackage
bool backupPackage(const std::string &packageName)
create tar.gz of all changed files in a Package
Definition: RpmDb.cc:1925
zypp::target::rpm::RpmHeader::constPtr
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:64
zypp::Edition
Edition represents [epoch:]version[-release]
Definition: Edition.h:61
zypp::target::rpm::RpmDb::processConfigFiles
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:1477
zypp::base::ReferenceCounted
Base class for reference counted objects.
Definition: ReferenceCounted.h:34
zypp::target::rpm::RpmDb::systemKill
void systemKill()
Forcably kill the system process.
Definition: RpmDb.cc:1470
zypp::target::rpm::RpmDb::importZyppKeyRingTrustedKeys
void importZyppKeyRingTrustedKeys()
iterates through zypp keyring and import all non existant keys into rpm keyring
Definition: RpmDb.cc:687
zypp::target::rpm::RpmDb::checkPackage
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,...
Definition: RpmDb.cc:1270
zypp::target::rpm::RpmDb::CHK_NOTFOUND
@ CHK_NOTFOUND
Definition: RpmDb.h:354
zypp::target::rpm::RpmDb::exportTrustedKeysInZyppKeyRing
void exportTrustedKeysInZyppKeyRing()
insert all rpm trusted keys into zypp trusted keyring
Definition: RpmDb.cc:690
zypp::target::rpm::RpmDb::_root
Pathname _root
Root directory for all operations.
Definition: RpmDb.h:66
zypp::Package::constPtr
TraitsType::constPtrType constPtr
Definition: Package.h:38
zypp::ExternalProgram
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
Definition: ExternalProgram.h:60
zypp::target::rpm::RpmDb::systemReadLine
bool systemReadLine(std::string &line)
Read a line from the general rpm query.
Definition: RpmDb.cc:1395
Pathname.h
zypp::target::rpm::RpmDb::installPackage
void installPackage(const Pathname &filename, RpmInstFlags flags=RPMINST_NONE)
install rpm package
Definition: RpmDb.cc:1574
report
callback::SendReport< DownloadProgressReport > * report
Definition: MediaCurl.cc:70
zypp::target::rpm::RpmDb::CHK_NOTTRUSTED
@ CHK_NOTTRUSTED
Definition: RpmDb.h:356
KeyRing.h
zypp::target::rpm::RpmDb::importPubkey
void importPubkey(const PublicKey &pubkey_r)
Import ascii armored public key in file pubkey_r.
Definition: RpmDb.cc:699
zypp::target::rpm::RpmDb::queryChangedFiles
bool queryChangedFiles(FileList &fileList, const std::string &packageName)
determine which files of an installed package have been modified.
Definition: RpmDb.cc:1282
Package.h
zypp::target::rpm::operator<<
std::ostream & operator<<(std::ostream &str, const librpmDb::db_const_iterator &obj)
Definition: librpmDb.cc:693
zypp::target::rpm::RpmDb::hasProvides
bool hasProvides(const std::string &tag_r) const
Return true if at least one package provides a certain tag.
Definition: RpmDb.cc:1014
RpmCallbacks.h
zypp::target::rpm::RpmDb::getData
void getData(const std::string &name_r, RpmHeader::constPtr &result_r) const
Get an installed packages data from rpmdb.
Definition: RpmDb.cc:1084
zypp::target::rpm::RpmDb::process
ExternalProgram * process
The connection to the rpm process.
Definition: RpmDb.h:276
zypp::target::rpm::RpmDb::SYNC_TO_KEYRING
@ SYNC_TO_KEYRING
export rpm trusted keys into zypp trusted keyring
Definition: RpmDb.h:254
zypp::base::NonCopyable
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
zypp::target::rpm::RpmDb::hasPackage
bool hasPackage(const std::string &name_r) const
Return true if package is installed.
Definition: RpmDb.cc:1056
zypp::target::rpm::RpmDb::pubkeys
std::list< PublicKey > pubkeys() const
Return the long ids of all installed public keys.
Definition: RpmDb.cc:879
zypp::target::rpm::RpmDb::~RpmDb
~RpmDb()
Destructor.
Definition: RpmDb.cc:238
ZYppCallbacks.h
zypp::target::rpm::RpmDb::syncTrustedKeys
void syncTrustedKeys(SyncTrustedKeyBits mode_r=SYNC_BOTH)
Sync trusted keys stored in rpm database and zypp trusted keyring.
Definition: RpmDb.cc:586
zypp::target::rpm::RpmDb
Interface to the rpm program.
Definition: RpmDb.h:48
zypp::target::rpm::RpmDb::_dbPath
Pathname _dbPath
Directory that contains the rpmdb.
Definition: RpmDb.h:71
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::target::rpm::RpmDb::_packagebackups
bool _packagebackups
create package backups?
Definition: RpmDb.h:325
zypp::target::rpm::RpmDb::doInstallPackage
void doInstallPackage(const Pathname &filename, RpmInstFlags flags, callback::SendReport< RpmInstallReport > &report)
Definition: RpmDb.cc:1604
zypp::target::rpm::RpmDb::SyncTrustedKeyBits
SyncTrustedKeyBits
Sync mode for syncTrustedKeys.
Definition: RpmDb.h:253
zypp::ExternalProgram::Stderr_Disposition
Stderr_Disposition
Define symbols for different policies on the handling of stderr.
Definition: ExternalProgram.h:70
zypp::target::rpm::RpmDb::CHK_NOKEY
@ CHK_NOKEY
Definition: RpmDb.h:357
zypp::target::rpm::RpmDb::root
const Pathname & root() const
Definition: RpmDb.h:89
zypp::target::rpm::RpmDb::rebuildDatabase
void rebuildDatabase()
Rebuild the rpm database (rpm –rebuilddb).
Definition: RpmDb.cc:387
zypp::target::rpm::RpmDb::hasFile
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:970
zypp::target::rpm::RpmDb::removePackage
void removePackage(const std::string &name_r, RpmInstFlags flags=RPMINST_NONE)
remove rpm package
Definition: RpmDb.cc:1769
zypp::target::rpm::RpmDb::dbPath
const Pathname & dbPath() const
Definition: RpmDb.h:97
zypp::target::rpm::RPMINST_NONE
@ RPMINST_NONE
Definition: RpmFlags.h:39
zypp::target::rpm::RpmDb::hasRequiredBy
bool hasRequiredBy(const std::string &tag_r) const
Return true if at least one package requires a certain tag.
Definition: RpmDb.cc:1028
zypp::PublicKey
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:276
zypp::target::rpm::RpmDb::createPackageBackups
void createPackageBackups(bool yes)
whether to create package backups during install or removal
Definition: RpmDb.h:459
zypp::target::rpm::RpmDb::doRemovePackage
void doRemovePackage(const std::string &name_r, RpmInstFlags flags, callback::SendReport< RpmRemoveReport > &report)
Definition: RpmDb.cc:1800
zypp::target::rpm::RpmDb::fileList
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 !...
Definition: RpmDb.cc:941
zypp::filesystem::Pathname::empty
bool empty() const
Test for an empty path.
Definition: Pathname.h:114
zypp::target::rpm::RpmDb::SYNC_FROM_KEYRING
@ SYNC_FROM_KEYRING
import zypp trusted keys into rpm database.
Definition: RpmDb.h:255
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:45
zypp::target::rpm::RpmDb::CheckPackageDetail
Detailed rpm signature check log messages A single multiline message if CHK_OK.
Definition: RpmDb.h:367
zypp::target::rpm::RpmDb::getBackupPath
Pathname getBackupPath(void)
get backup dir for rpm config files
Definition: RpmDb.h:424
zypp::target::rpm::RpmDb::FileList
std::set< std::string > FileList
Definition: RpmDb.h:345
zypp::target::rpm::RpmDb::RpmDb
RpmDb()
Constructor.
Definition: RpmDb.cc:219
zypp::target::rpm::RpmDb::CHK_ERROR
@ CHK_ERROR
Definition: RpmDb.h:358
RpmFlags.h
zypp::target::rpm::RpmDb::error_message
std::string error_message
Error message from running rpm as external program.
Definition: RpmDb.h:319
str
String related utilities and Regular expression matching.
zypp::target::rpm::RpmDb::SYNC_BOTH
@ SYNC_BOTH
Definition: RpmDb.h:256
zypp::target::rpm::RpmDb::exit_code
int exit_code
The exit code of the rpm process, or -1 if not yet known.
Definition: RpmDb.h:313
zypp::target::rpm::RpmDb::initDatabase
void initDatabase(Pathname root_r=Pathname(), bool doRebuild_r=false)
Prepare access to the rpm database at /var/lib/rpm.
Definition: RpmDb.cc:264
zypp::target::rpm::RpmDb::Error
class InstTargetError Error
Default error class.
Definition: RpmDb.h:54
zypp::target::rpm::RpmDb::CHK_FAIL
@ CHK_FAIL
Definition: RpmDb.h:355
zypp::target::rpm::RpmDb::RpmArgVec
std::vector< const char * > RpmArgVec
Definition: RpmDb.h:278
zypp::target::rpm::RpmDb::whoOwnsFile
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:996
zypp::target::rpm::RpmDb::dumpOn
virtual std::ostream & dumpOn(std::ostream &str) const
Dump debug info.
Definition: RpmDb.cc:253
zypp::target::rpm::RpmDb::systemStatus
int systemStatus()
Return the exit status of the general rpm process, closing the connection if not already done.
Definition: RpmDb.cc:1447