libzypp: zypp/target/rpm/RpmDb.h Source File

libzypp 17.38.10

RpmDb.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12
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-core/Pathname.h>
25#include <zypp-core/ExternalProgram.h>
26
27#include <zypp/Package.h>
28#include <zypp/KeyRing.h>
29
30#include <zypp/target/rpm/RpmFlags.h>
31#include <zypp/target/rpm/RpmHeader.h>
32#include <zypp/target/rpm/RpmCallbacks.h>
33#include <zypp/target/rpm/librpmDb.h>
34#include <zypp/ZYppCallbacks.h>
35
36namespace zypp
37{
38namespace target
39{
40class RpmPostTransCollector;
41namespace rpm
42{
43
45//
46// CLASS NAME : RpmDb
50 class ZYPP_API RpmDb : public base::ReferenceCounted, private base::NonCopyable
51{
52public:
53
57 using Error = class InstTargetError;
58
64 struct db_const_iterator : public librpmDb::db_const_iterator
65 {
66 private:
67 friend class RpmDb;
68 db_const_iterator()
69 : librpmDb::db_const_iterator { nullptr }
70 {}
71 db_const_iterator( const Pathname & root_r, const Pathname & dbPath_r )
72 : librpmDb::db_const_iterator { root_r, dbPath_r }
73 {}
74 };
75
77 //
78 // INITALISATION
79 //
81private:
82
86 Pathname _root;
87
91 Pathname _dbPath;
92
93public:
94
99 RpmDb();
100
104 ~RpmDb() override;
105
109 const Pathname & root() const
110 {
111 return _root;
112 }
113
117 const Pathname & dbPath() const
118 {
119 return _dbPath;
120 }
121
125 bool initialized() const
126 {
127 return( ! _root.empty() );
128 }
129
133 db_const_iterator dbConstIterator() const;
134
149 void initDatabase( Pathname root_r = Pathname(), bool doRebuild_r = false );
150
159 void closeDatabase();
160
167 void rebuildDatabase();
168
175 void importPubkey( const PublicKey & pubkey_r );
176
183 void removePubkey( const PublicKey & pubkey_r );
184
188 std::list<PublicKey> pubkeys() const;
189
193 std::set<Edition> pubkeyEditions() const;
194
196 //
197 // Direct RPM database retrieval via librpm.
198 //
200public:
201
207 std::list<FileInfo> fileList( const std::string & name_r, const Edition & edition_r ) const;
208
213 bool hasFile( const std::string & file_r, const std::string & name_r = "" ) const;
214
219 std::string whoOwnsFile( const std::string & file_r ) const;
220
224 bool hasProvides( const std::string & tag_r ) const;
225
229 bool hasRequiredBy( const std::string & tag_r ) const;
230
234 bool hasConflicts( const std::string & tag_r ) const;
235
239 bool hasPackage( const std::string & name_r ) const;
240
244 bool hasPackage( const std::string & name_r, const Edition & ed_r ) const;
245
257 void getData( const std::string & name_r,
258 RpmHeader::constPtr & result_r ) const;
259
269 void getData( const std::string & name_r, const Edition & ed_r,
270 RpmHeader::constPtr & result_r ) const;
271
273 //
275public:
277 enum SyncTrustedKeyBits
278 {
279 SYNC_TO_KEYRING = 1<<0,
280 SYNC_FROM_KEYRING = 1<<1,
281 SYNC_BOTH = SYNC_TO_KEYRING | SYNC_FROM_KEYRING
282 };
283
286 void syncTrustedKeys( SyncTrustedKeyBits mode_r = SYNC_BOTH );
291 void importZyppKeyRingTrustedKeys();
295 void exportTrustedKeysInZyppKeyRing();
296
297private:
301 ExternalProgram *process;
302
303 using RpmArgVec = std::vector<const char *>;
304
314 void run_rpm( const RpmArgVec& options,
315 ExternalProgram::Stderr_Disposition stderr_disp =
316 ExternalProgram::Stderr_To_Stdout);
317
318
322 bool systemReadLine(std::string &line);
323
328 int systemStatus();
329
333 void systemKill();
334
338 int exit_code;
339
344 std::string error_message;
345
347 Pathname _backuppath;
348
350 bool _packagebackups;
351
361 void processConfigFiles(const std::string& line,
362 const std::string& name,
363 const char* typemsg,
364 const char* difffailmsg,
365 const char* diffgenmsg);
366
367
368public:
369
370 using FileList = std::set<std::string>;
371
376 enum CheckPackageResult
377 {
378 CHK_OK = 0,
379 CHK_NOTFOUND = 1,
380 CHK_FAIL = 2,
381 CHK_NOTTRUSTED = 3,
382 CHK_NOKEY = 4,
383 CHK_ERROR = 5,
384 CHK_NOSIG = 6,
385 };
386
391 struct CheckPackageDetail : std::vector<std::pair<CheckPackageResult,std::string>>
392 {};
393
404 CheckPackageResult checkPackage( const Pathname & path_r, CheckPackageDetail & detail_r );
406 CheckPackageResult checkPackage( const Pathname & path_r );
407
418 CheckPackageResult checkPackageSignature( const Pathname & path_r, CheckPackageDetail & detail_r );
419
430 void installPackage ( const Pathname & filename, RpmInstFlags flags = RPMINST_NONE );
432 void installPackage( const Pathname & filename, RpmInstFlags flags, RpmPostTransCollector* postTransCollector_r );
433
444 void removePackage( const std::string & name_r, RpmInstFlags flags = RPMINST_NONE );
445 void removePackage( Package::constPtr package, RpmInstFlags flags = RPMINST_NONE );
447 void removePackage( const std::string & name_r, RpmInstFlags flags, RpmPostTransCollector* postTransCollector_r );
448 void removePackage( const Package::constPtr& package, RpmInstFlags flags, RpmPostTransCollector* postTransCollector_r );
449
454 int runposttrans( const Pathname & filename_r, const std::function<void(const std::string&)>& output_r );
455
460 Pathname getBackupPath (void)
461 {
462 return _backuppath;
463 }
464
472 bool backupPackage(const std::string& packageName);
473
480 bool backupPackage(const Pathname& filename);
481
487 void setBackupPath(const Pathname& path);
488
495 void createPackageBackups(bool yes)
496 {
497 _packagebackups = yes;
498 }
499
510 bool queryChangedFiles(FileList & fileList, const std::string& packageName);
511
512public:
513
517 std::ostream & dumpOn( std::ostream & str ) const override;
518
519protected:
520 void doRemovePackage( const std::string & name_r, RpmInstFlags flags, RpmPostTransCollector* postTransCollector_r, callback::SendReport<RpmRemoveReport> & report );
521 void doInstallPackage( const Pathname & filename, RpmInstFlags flags, RpmPostTransCollector* postTransCollector_r, callback::SendReport<RpmInstallReport> & report );
522 void doRebuildDatabase(callback::SendReport<RebuildDBReport> & report);
523};
524
526std::ostream & operator<<( std::ostream & str, RpmDb::CheckPackageResult obj ) ZYPP_API;
527
529std::ostream & operator<<( std::ostream & str, const RpmDb::CheckPackageDetail & obj ) ZYPP_API;
530
531} // namespace rpm
532} // namespace target
533} // namespace zypp
534
535#endif // ZYPP_TARGET_RPM_RPMDB_H
ExternalProgram.h
KeyRing.h
Package.h
Pathname.h
RpmCallbacks.h
RpmFlags.h
RpmHeader.h
ZYppCallbacks.h
zypp::Edition
Edition represents [epoch:]version[-release].
Definition Edition.h:60
zypp::ExternalProgram
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
Definition ExternalProgram.h:64
zypp::ExternalProgram::Stderr_Disposition
Stderr_Disposition
Define symbols for different policies on the handling of stderr.
Definition ExternalProgram.h:74
zypp::ExternalProgram::Stderr_To_Stdout
@ Stderr_To_Stdout
Definition ExternalProgram.h:77
zypp::Package::constPtr
TraitsType::constPtrType constPtr
Definition Package.h:39
zypp::PublicKey
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition PublicKey.h:375
zypp::base::ReferenceCounted
Base class for reference counted objects.
Definition ReferenceCounted.h:35
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::target::RpmPostTransCollector
Extract and remember posttrans scripts for later execution.
Definition RpmPostTransCollector.h:41
zypp::target::rpm::RpmDb::error_message
std::string error_message
Error message from running rpm as external program.
Definition RpmDb.h:344
zypp::target::rpm::RpmDb::RpmArgVec
std::vector< const char * > RpmArgVec
Definition RpmDb.h:303
zypp::target::rpm::RpmDb::Error
class InstTargetError Error
Default error class.
Definition RpmDb.h:57
zypp::target::rpm::RpmDb::installPackage
void installPackage(const Pathname &filename, RpmInstFlags flags=RPMINST_NONE)
install rpm package
Definition RpmDb.cc:1652
zypp::target::rpm::RpmDb::_backuppath
Pathname _backuppath
/var/adm/backup
Definition RpmDb.h:347
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:1425
zypp::target::rpm::RpmDb::runposttrans
int runposttrans(const Pathname &filename_r, const std::function< void(const std::string &)> &output_r)
Run collected posttrans and transfiletrigger(postun|in) if rpm --runposttrans is supported.
Definition RpmDb.cc:2020
zypp::target::rpm::RpmDb::initialized
bool initialized() const
Definition RpmDb.h:125
zypp::target::rpm::RpmDb::process
ExternalProgram * process
The connection to the rpm process.
Definition RpmDb.h:301
zypp::target::rpm::RpmDb::SyncTrustedKeyBits
SyncTrustedKeyBits
Sync mode for syncTrustedKeys.
Definition RpmDb.h:278
zypp::target::rpm::RpmDb::SYNC_TO_KEYRING
@ SYNC_TO_KEYRING
export rpm trusted keys into zypp trusted keyring
Definition RpmDb.h:279
zypp::target::rpm::RpmDb::SYNC_FROM_KEYRING
@ SYNC_FROM_KEYRING
import zypp trusted keys into rpm database.
Definition RpmDb.h:280
zypp::target::rpm::RpmDb::SYNC_BOTH
@ SYNC_BOTH
Definition RpmDb.h:281
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:1527
zypp::target::rpm::RpmDb::FileList
std::set< std::string > FileList
Definition RpmDb.h:370
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:1354
zypp::target::rpm::RpmDb::systemKill
void systemKill()
Forcably kill the system process.
Definition RpmDb.cc:1550
zypp::target::rpm::RpmDb::root
const Pathname & root() const
Definition RpmDb.h:109
zypp::target::rpm::RpmDb::RpmDb
RpmDb()
Constructor.
Definition RpmDb.cc:228
zypp::target::rpm::RpmDb::removePackage
void removePackage(const std::string &name_r, RpmInstFlags flags=RPMINST_NONE)
remove rpm package
Definition RpmDb.cc:1854
zypp::target::rpm::RpmDb::createPackageBackups
void createPackageBackups(bool yes)
whether to create package backups during install or removal
Definition RpmDb.h:495
zypp::target::rpm::RpmDb::dbPath
const Pathname & dbPath() const
Definition RpmDb.h:117
zypp::target::rpm::RpmDb::_dbPath
Pathname _dbPath
Directory that contains the rpmdb.
Definition RpmDb.h:91
zypp::target::rpm::RpmDb::_packagebackups
bool _packagebackups
create package backups?
Definition RpmDb.h:350
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:1348
zypp::target::rpm::RpmDb::getBackupPath
Pathname getBackupPath(void)
get backup dir for rpm config files
Definition RpmDb.h:460
zypp::target::rpm::RpmDb::_root
Pathname _root
Root directory for all operations.
Definition RpmDb.h:86
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:338
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:1557
zypp::target::rpm::RpmDb::CheckPackageResult
CheckPackageResult
checkPackage result
Definition RpmDb.h:377
zypp::target::rpm::RpmDb::CHK_ERROR
@ CHK_ERROR
Definition RpmDb.h:383
zypp::target::rpm::RpmDb::CHK_NOTTRUSTED
@ CHK_NOTTRUSTED
Definition RpmDb.h:381
zypp::target::rpm::RpmDb::CHK_NOSIG
@ CHK_NOSIG
Definition RpmDb.h:384
zypp::target::rpm::RpmDb::CHK_NOKEY
@ CHK_NOKEY
Definition RpmDb.h:382
zypp::target::rpm::RpmDb::CHK_FAIL
@ CHK_FAIL
Definition RpmDb.h:380
zypp::target::rpm::RpmDb::CHK_NOTFOUND
@ CHK_NOTFOUND
Definition RpmDb.h:379
zypp::target::rpm::RpmDb::CHK_OK
@ CHK_OK
Definition RpmDb.h:378
zypp::target::rpm::RpmDb::systemReadLine
bool systemReadLine(std::string &line)
Read a line from the general rpm query.
Definition RpmDb.cc:1474
zypp::target::rpm::RpmHeader::constPtr
intrusive_ptr< const RpmHeader > constPtr
Definition RpmHeader.h:65
zypp::target::rpm::librpmDb::db_const_iterator
Subclass to retrieve rpm database content.
Definition librpmDb.h:198
zypp::target::rpm::librpmDb::db_const_iterator::librpmDb
friend class librpmDb
Definition librpmDb.h:202
librpmDb.h
str
String related utilities and Regular expression matching.
zypp::base::NonCopyable
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition NonCopyable.h:26
zypp::target::rpm
Definition KeyRing.h:327
zypp::target::rpm::RPMINST_NONE
@ RPMINST_NONE
Definition RpmFlags.h:39
zypp::target::rpm::operator<<
std::ostream & operator<<(std::ostream &str, const librpmDb::db_const_iterator &obj)
relates: librpmDb::db_const_iterator stream output
Definition librpmDb.cc:412
zypp::target
Definition KeyRing.h:325
zypp::target::dumpOn
std::ostream & dumpOn(std::ostream &str, const RpmPostTransCollector::Impl &obj)
relates: RpmPostTransCollector::Impl Verbose stream output
Definition RpmPostTransCollector.cc:401
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::ZYPP_API
const Arch Arch_empty ZYPP_API
relates: Arch This is an empty Arch represented by an empty string.
Definition Arch.h:173
zypp::callback::SendReport
Definition Callback.h:237
zypp::target::rpm::RpmDb::CheckPackageDetail
Detailed rpm signature check log messages A single multiline message if CHK_OK.
Definition RpmDb.h:392
zypp::target::rpm::RpmDb::db_const_iterator::db_const_iterator
db_const_iterator(const Pathname &root_r, const Pathname &dbPath_r)
Definition RpmDb.h:71
zypp::target::rpm::RpmDb::db_const_iterator::db_const_iterator
db_const_iterator()
Definition RpmDb.h:68
zypp::target::rpm::RpmDb::db_const_iterator::RpmDb
friend class RpmDb
Definition RpmDb.h:67