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
zypp::target::rpm::RpmDb::initialized
bool initialized() const
Definition: RpmDb.h:111
ExternalProgram.h
zypp::ExternalProgram::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:1347
zypp::target::rpm::RpmDb::removePubkey
void removePubkey(const PublicKey &pubkey_r)
Remove a public key from the rpm database.
Definition: RpmDb.cc:811
zypp::target::rpm::RpmDb::doRebuildDatabase
void doRebuildDatabase(callback::SendReport< RebuildDBReport > &report)
Definition: RpmDb.cc:404
zypp::target::rpm::RpmDb::CHK_NOSIG
Definition: RpmDb.h:369
zypp::target::rpm::RpmDb::CheckPackageResult
CheckPackageResult
checkPackage result
Definition: RpmDb.h:361
zypp::target::rpm::RpmDb::closeDatabase
void closeDatabase()
Block further access to the rpm database and go back to uninitialized state.
Definition: RpmDb.cc:358
zypp::callback::SendReport
Definition: Callback.h:236
zypp::target::rpm::RpmDb::pubkeyEditions
std::set< Edition > pubkeyEditions() const
Return the edition of all installed public keys.
Definition: RpmDb.cc:916
RpmHeader.h
zypp::target::rpm::RpmDb::_backuppath
Pathname _backuppath
/var/adm/backup
Definition: RpmDb.h:328
zypp::target::rpm::RpmDb::setBackupPath
void setBackupPath(const Pathname &path)
set path where package backups are stored
Definition: RpmDb.cc:2051
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:1041
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:1275
zypp::target::rpm::RpmDb::CHK_OK
Definition: RpmDb.h:363
zypp::target::rpm::RpmDb::backupPackage
bool backupPackage(const std::string &packageName)
create tar.gz of all changed files in a Package
Definition: RpmDb.cc:1924
zypp::target::rpm::RpmHeader::constPtr
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:64
zypp::Edition
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
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:1476
zypp::base::ReferenceCounted
Base class for reference counted objects.
Definition: ReferenceCounted.h:33
zypp::target::rpm::RpmDb::systemKill
void systemKill()
Forcably kill the system process.
Definition: RpmDb.cc:1469
zypp::target::rpm::RpmDb::importZyppKeyRingTrustedKeys
void importZyppKeyRingTrustedKeys()
iterates through zypp keyring and import all non existant keys into rpm keyring
Definition: RpmDb.cc:686
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:1269
zypp::target::rpm::RpmDb::CHK_NOTFOUND
Definition: RpmDb.h:364
zypp::target::rpm::RpmDb::exportTrustedKeysInZyppKeyRing
void exportTrustedKeysInZyppKeyRing()
insert all rpm trusted keys into zypp trusted keyring
Definition: RpmDb.cc:689
zypp::target::rpm::RpmDb::_root
Pathname _root
Root directory for all operations.
Definition: RpmDb.h:72
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:59
zypp::target::rpm::RpmDb::systemReadLine
bool systemReadLine(std::string &line)
Read a line from the general rpm query.
Definition: RpmDb.cc:1394
Pathname.h
zypp::target::rpm::RpmDb::installPackage
void installPackage(const Pathname &filename, RpmInstFlags flags=RPMINST_NONE)
install rpm package
Definition: RpmDb.cc:1573
report
callback::SendReport< DownloadProgressReport > * report
Definition: MediaCurl.cc:70
zypp::target::rpm::RpmDb::CHK_NOTTRUSTED
Definition: RpmDb.h:366
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:698
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:1281
Package.h
zypp::target::rpm::operator<<
std::ostream & operator<<(std::ostream &str, const librpmDb::db_const_iterator &obj)
Definition: librpmDb.cc:694
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:1013
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:1083
zypp::target::rpm::RpmDb::process
ExternalProgram * process
The connection to the rpm process.
Definition: RpmDb.h:282
zypp::target::rpm::RpmDb::SYNC_TO_KEYRING
export rpm trusted keys into zypp trusted keyring
Definition: RpmDb.h:260
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:1055
zypp::target::rpm::RpmDb::pubkeys
std::list< PublicKey > pubkeys() const
Return the long ids of all installed public keys.
Definition: RpmDb.cc:878
zypp::target::rpm::RpmDb::~RpmDb
~RpmDb()
Destructor.
Definition: RpmDb.cc:237
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:585
zypp::target::rpm::RpmDb
Interface to the rpm program.
Definition: RpmDb.h:47
zypp::target::rpm::RpmDb::_dbPath
Pathname _dbPath
Directory that contains the rpmdb.
Definition: RpmDb.h:77
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::target::rpm::RpmDb::_packagebackups
bool _packagebackups
create package backups?
Definition: RpmDb.h:331
zypp::target::rpm::RpmDb::doInstallPackage
void doInstallPackage(const Pathname &filename, RpmInstFlags flags, callback::SendReport< RpmInstallReport > &report)
Definition: RpmDb.cc:1603
zypp::target::rpm::RpmDb::SyncTrustedKeyBits
SyncTrustedKeyBits
Sync mode for syncTrustedKeys.
Definition: RpmDb.h:258
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
Definition: RpmDb.h:367
zypp::target::rpm::RpmDb::root
const Pathname & root() const
Definition: RpmDb.h:95
zypp::target::rpm::RpmDb::rebuildDatabase
void rebuildDatabase()
Rebuild the rpm database (rpm –rebuilddb).
Definition: RpmDb.cc:386
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:969
zypp::target::rpm::RpmDb::removePackage
void removePackage(const std::string &name_r, RpmInstFlags flags=RPMINST_NONE)
remove rpm package
Definition: RpmDb.cc:1768
zypp::target::rpm::RpmDb::dbPath
const Pathname & dbPath() const
Definition: RpmDb.h:103
zypp::target::rpm::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:1027
zypp::PublicKey
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:275
zypp::target::rpm::RpmDb::createPackageBackups
void createPackageBackups(bool yes)
whether to create package backups during install or removal
Definition: RpmDb.h:469
zypp::target::rpm::RpmDb::doRemovePackage
void doRemovePackage(const std::string &name_r, RpmInstFlags flags, callback::SendReport< RpmRemoveReport > &report)
Definition: RpmDb.cc:1799
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:940
zypp::filesystem::Pathname::empty
bool empty() const
Test for an empty path.
Definition: Pathname.h:114
zypp::target::rpm::RpmDb::SYNC_FROM_KEYRING
import zypp trusted keys into rpm database.
Definition: RpmDb.h:261
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:44
zypp::target::rpm::RpmDb::CheckPackageDetail
Detailed rpm signature check log messages A single multiline message if CHK_OK.
Definition: RpmDb.h:376
zypp::target::rpm::RpmDb::getBackupPath
Pathname getBackupPath(void)
get backup dir for rpm config files
Definition: RpmDb.h:434
zypp::target::rpm::RpmDb::FileList
std::set< std::string > FileList
Definition: RpmDb.h:355
zypp::target::rpm::RpmDb::RpmDb
RpmDb()
Constructor.
Definition: RpmDb.cc:218
zypp::target::rpm::RpmDb::CHK_ERROR
Definition: RpmDb.h:368
RpmFlags.h
zypp::target::rpm::RpmDb::error_message
std::string error_message
Error message from running rpm as external program.
Definition: RpmDb.h:325
str
String related utilities and Regular expression matching.
zypp::target::rpm::RpmDb::SYNC_BOTH
Definition: RpmDb.h:262
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:319
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:263
zypp::target::rpm::RpmDb::Error
class InstTargetError Error
Default error class.
Definition: RpmDb.h:54
zypp::target::rpm::RpmDb::CHK_FAIL
Definition: RpmDb.h:365
zypp::target::rpm::RpmDb::RpmArgVec
std::vector< const char * > RpmArgVec
Definition: RpmDb.h:284
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:995
zypp::target::rpm::RpmDb::dumpOn
virtual std::ostream & dumpOn(std::ostream &str) const
Dump debug info.
Definition: RpmDb.cc:252
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:1446