libzypp 17.31.0
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
34namespace zypp
35{
36namespace target
37{
38namespace rpm
39{
40
42//
43// CLASS NAME : RpmDb
48{
49public:
50
54 typedef class InstTargetError Error;
55
57 //
58 // INITALISATION
59 //
61private:
62
67
72
73public:
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 //
175public:
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 //
250public:
253 {
257 };
271
272private:
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
343public:
344
345 typedef std::set<std::string> FileList;
346
352 {
353 CHK_OK = 0,
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
476public:
477
481 virtual std::ostream & dumpOn( std::ostream & str ) const;
482
483protected:
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
490std::ostream & operator<<( std::ostream & str, RpmDb::CheckPackageResult obj );
491
493std::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
Edition represents [epoch:]version[-release]
Definition: Edition.h:61
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
Stderr_Disposition
Define symbols for different policies on the handling of stderr.
TraitsType::constPtrType constPtr
Definition: Package.h:38
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:359
Base class for reference counted objects.
bool empty() const
Test for an empty path.
Definition: Pathname.h:114
Interface to the rpm program.
Definition: RpmDb.h:48
void getData(const std::string &name_r, RpmHeader::constPtr &result_r) const
Get an installed packages data from rpmdb.
Definition: RpmDb.cc:1081
void doRebuildDatabase(callback::SendReport< RebuildDBReport > &report)
Definition: RpmDb.cc:402
bool queryChangedFiles(FileList &fileList, const std::string &packageName)
determine which files of an installed package have been modified.
Definition: RpmDb.cc:1363
std::string error_message
Error message from running rpm as external program.
Definition: RpmDb.h:319
bool hasRequiredBy(const std::string &tag_r) const
Return true if at least one package requires a certain tag.
Definition: RpmDb.cc:1025
virtual std::ostream & dumpOn(std::ostream &str) const
Dump debug info.
Definition: RpmDb.cc:255
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:993
void exportTrustedKeysInZyppKeyRing()
insert all rpm trusted keys into zypp trusted keyring
Definition: RpmDb.cc:687
void importPubkey(const PublicKey &pubkey_r)
Import ascii armored public key in file pubkey_r.
Definition: RpmDb.cc:696
void installPackage(const Pathname &filename, RpmInstFlags flags=RPMINST_NONE)
install rpm package
Definition: RpmDb.cc:1655
Pathname _backuppath
/var/adm/backup
Definition: RpmDb.h:322
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:1428
void initDatabase(Pathname root_r=Pathname(), bool doRebuild_r=false)
Prepare access to the rpm database below root_r.
Definition: RpmDb.cc:266
bool initialized() const
Definition: RpmDb.h:105
ExternalProgram * process
The connection to the rpm process.
Definition: RpmDb.h:276
SyncTrustedKeyBits
Sync mode for syncTrustedKeys.
Definition: RpmDb.h:253
@ SYNC_TO_KEYRING
export rpm trusted keys into zypp trusted keyring
Definition: RpmDb.h:254
@ SYNC_FROM_KEYRING
import zypp trusted keys into rpm database.
Definition: RpmDb.h:255
std::list< PublicKey > pubkeys() const
Return the long ids of all installed public keys.
Definition: RpmDb.cc:876
std::set< Edition > pubkeyEditions() const
Return the edition of all installed public keys.
Definition: RpmDb.cc:914
int systemStatus()
Return the exit status of the general rpm process, closing the connection if not already done.
Definition: RpmDb.cc:1528
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:1357
bool backupPackage(const std::string &packageName)
create tar.gz of all changed files in a Package
Definition: RpmDb.cc:2011
bool hasProvides(const std::string &tag_r) const
Return true if at least one package provides a certain tag.
Definition: RpmDb.cc:1011
void systemKill()
Forcably kill the system process.
Definition: RpmDb.cc:1551
const Pathname & root() const
Definition: RpmDb.h:89
void removePubkey(const PublicKey &pubkey_r)
Remove a public key from the rpm database.
Definition: RpmDb.cc:809
RpmDb()
Constructor.
Definition: RpmDb.cc:221
void removePackage(const std::string &name_r, RpmInstFlags flags=RPMINST_NONE)
remove rpm package
Definition: RpmDb.cc:1852
void doInstallPackage(const Pathname &filename, RpmInstFlags flags, callback::SendReport< RpmInstallReport > &report)
Definition: RpmDb.cc:1685
void createPackageBackups(bool yes)
whether to create package backups during install or removal
Definition: RpmDb.h:459
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:938
const Pathname & dbPath() const
Definition: RpmDb.h:97
Pathname _dbPath
Directory that contains the rpmdb.
Definition: RpmDb.h:71
void closeDatabase()
Block further access to the rpm database and go back to uninitialized state.
Definition: RpmDb.cc:356
void setBackupPath(const Pathname &path)
set path where package backups are stored
Definition: RpmDb.cc:2138
void doRemovePackage(const std::string &name_r, RpmInstFlags flags, callback::SendReport< RpmRemoveReport > &report)
Definition: RpmDb.cc:1883
bool _packagebackups
create package backups?
Definition: RpmDb.h:325
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:1351
void importZyppKeyRingTrustedKeys()
iterates through zypp keyring and import all non-existent keys into rpm keyring
Definition: RpmDb.cc:684
Pathname getBackupPath(void)
get backup dir for rpm config files
Definition: RpmDb.h:424
Pathname _root
Root directory for all operations.
Definition: RpmDb.h:66
class InstTargetError Error
Default error class.
Definition: RpmDb.h:54
bool hasConflicts(const std::string &tag_r) const
Return true if at least one package conflicts with a certain tag.
Definition: RpmDb.cc:1039
std::vector< const char * > RpmArgVec
Definition: RpmDb.h:278
int exit_code
The exit code of the rpm process, or -1 if not yet known.
Definition: RpmDb.h:313
void syncTrustedKeys(SyncTrustedKeyBits mode_r=SYNC_BOTH)
Sync trusted keys stored in rpm database and zypp trusted keyring.
Definition: RpmDb.cc:583
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:1558
CheckPackageResult
checkPackage result
Definition: RpmDb.h:352
~RpmDb()
Destructor.
Definition: RpmDb.cc:240
bool hasPackage(const std::string &name_r) const
Return true if package is installed.
Definition: RpmDb.cc:1053
std::set< std::string > FileList
Definition: RpmDb.h:345
bool systemReadLine(std::string &line)
Read a line from the general rpm query.
Definition: RpmDb.cc:1475
void rebuildDatabase()
Rebuild the rpm database (rpm –rebuilddb).
Definition: RpmDb.cc:384
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:967
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:65
String related utilities and Regular expression matching.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
std::ostream & operator<<(std::ostream &str, const librpmDb::db_const_iterator &obj)
Definition: librpmDb.cc:706
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
Detailed rpm signature check log messages A single multiline message if CHK_OK.
Definition: RpmDb.h:367