libzypp 17.31.23
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
35namespace zypp
36{
37namespace target
38{
39class RpmPostTransCollector;
40namespace rpm
41{
42
44//
45// CLASS NAME : RpmDb
50{
51public:
52
56 typedef class InstTargetError Error;
57
59 //
60 // INITALISATION
61 //
63private:
64
69
74
75public:
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 //
177public:
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 //
252public:
255 {
259 };
273
274private:
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
345public:
346
347 typedef std::set<std::string> FileList;
348
354 {
355 CHK_OK = 0,
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
489public:
490
494 virtual std::ostream & dumpOn( std::ostream & str ) const;
495
496protected:
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
503std::ostream & operator<<( std::ostream & str, RpmDb::CheckPackageResult obj );
504
506std::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
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
Extract and remember posttrans scripts for later execution.
Interface to the rpm program.
Definition: RpmDb.h:50
void getData(const std::string &name_r, RpmHeader::constPtr &result_r) const
Get an installed packages data from rpmdb.
Definition: RpmDb.cc:1086
void doRebuildDatabase(callback::SendReport< RebuildDBReport > &report)
Definition: RpmDb.cc:407
bool queryChangedFiles(FileList &fileList, const std::string &packageName)
determine which files of an installed package have been modified.
Definition: RpmDb.cc:1368
std::string error_message
Error message from running rpm as external program.
Definition: RpmDb.h:321
bool hasRequiredBy(const std::string &tag_r) const
Return true if at least one package requires a certain tag.
Definition: RpmDb.cc:1030
virtual std::ostream & dumpOn(std::ostream &str) const
Dump debug info.
Definition: RpmDb.cc:260
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
void exportTrustedKeysInZyppKeyRing()
insert all rpm trusted keys into zypp trusted keyring
Definition: RpmDb.cc:692
void importPubkey(const PublicKey &pubkey_r)
Import ascii armored public key in file pubkey_r.
Definition: RpmDb.cc:701
void installPackage(const Pathname &filename, RpmInstFlags flags=RPMINST_NONE)
install rpm package
Definition: RpmDb.cc:1658
Pathname _backuppath
/var/adm/backup
Definition: RpmDb.h:324
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
void initDatabase(Pathname root_r=Pathname(), bool doRebuild_r=false)
Prepare access to the rpm database below root_r.
Definition: RpmDb.cc:271
bool initialized() const
Definition: RpmDb.h:107
ExternalProgram * process
The connection to the rpm process.
Definition: RpmDb.h:278
SyncTrustedKeyBits
Sync mode for syncTrustedKeys.
Definition: RpmDb.h:255
@ SYNC_TO_KEYRING
export rpm trusted keys into zypp trusted keyring
Definition: RpmDb.h:256
@ SYNC_FROM_KEYRING
import zypp trusted keys into rpm database.
Definition: RpmDb.h:257
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
std::list< PublicKey > pubkeys() const
Return the long ids of all installed public keys.
Definition: RpmDb.cc:881
std::set< Edition > pubkeyEditions() const
Return the edition of all installed public keys.
Definition: RpmDb.cc:919
int systemStatus()
Return the exit status of the general rpm process, closing the connection if not already done.
Definition: RpmDb.cc:1533
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
bool backupPackage(const std::string &packageName)
create tar.gz of all changed files in a Package
Definition: RpmDb.cc:2107
bool hasProvides(const std::string &tag_r) const
Return true if at least one package provides a certain tag.
Definition: RpmDb.cc:1016
void systemKill()
Forcably kill the system process.
Definition: RpmDb.cc:1556
const Pathname & root() const
Definition: RpmDb.h:91
void removePubkey(const PublicKey &pubkey_r)
Remove a public key from the rpm database.
Definition: RpmDb.cc:814
RpmDb()
Constructor.
Definition: RpmDb.cc:226
void removePackage(const std::string &name_r, RpmInstFlags flags=RPMINST_NONE)
remove rpm package
Definition: RpmDb.cc:1864
void createPackageBackups(bool yes)
whether to create package backups during install or removal
Definition: RpmDb.h:472
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:943
const Pathname & dbPath() const
Definition: RpmDb.h:99
Pathname _dbPath
Directory that contains the rpmdb.
Definition: RpmDb.h:73
void closeDatabase()
Block further access to the rpm database and go back to uninitialized state.
Definition: RpmDb.cc:361
void setBackupPath(const Pathname &path)
set path where package backups are stored
Definition: RpmDb.cc:2234
bool _packagebackups
create package backups?
Definition: RpmDb.h:327
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:1356
void importZyppKeyRingTrustedKeys()
iterates through zypp keyring and import all non-existent keys into rpm keyring
Definition: RpmDb.cc:689
void doInstallPackage(const Pathname &filename, RpmInstFlags flags, RpmPostTransCollector *postTransCollector_r, callback::SendReport< RpmInstallReport > &report)
Definition: RpmDb.cc:1694
Pathname getBackupPath(void)
get backup dir for rpm config files
Definition: RpmDb.h:437
Pathname _root
Root directory for all operations.
Definition: RpmDb.h:68
class InstTargetError Error
Default error class.
Definition: RpmDb.h:56
bool hasConflicts(const std::string &tag_r) const
Return true if at least one package conflicts with a certain tag.
Definition: RpmDb.cc:1044
std::vector< const char * > RpmArgVec
Definition: RpmDb.h:280
int exit_code
The exit code of the rpm process, or -1 if not yet known.
Definition: RpmDb.h:315
void syncTrustedKeys(SyncTrustedKeyBits mode_r=SYNC_BOTH)
Sync trusted keys stored in rpm database and zypp trusted keyring.
Definition: RpmDb.cc:588
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
CheckPackageResult
checkPackage result
Definition: RpmDb.h:354
~RpmDb()
Destructor.
Definition: RpmDb.cc:245
bool hasPackage(const std::string &name_r) const
Return true if package is installed.
Definition: RpmDb.cc:1058
void doRemovePackage(const std::string &name_r, RpmInstFlags flags, RpmPostTransCollector *postTransCollector_r, callback::SendReport< RpmRemoveReport > &report)
Definition: RpmDb.cc:1905
std::set< std::string > FileList
Definition: RpmDb.h:347
bool systemReadLine(std::string &line)
Read a line from the general rpm query.
Definition: RpmDb.cc:1480
void rebuildDatabase()
Rebuild the rpm database (rpm –rebuilddb).
Definition: RpmDb.cc:389
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
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:369