libzypp 17.37.17
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/Pathname.h>
26
27#include <zypp/Package.h>
28#include <zypp/KeyRing.h>
29
34#include <zypp/ZYppCallbacks.h>
35
36namespace zypp
37{
38namespace target
39{
41namespace rpm
42{
43
45//
46// CLASS NAME : RpmDb
51{
52public:
53
57 using Error = class InstTargetError;
58
65 {
66 private:
67 friend class RpmDb;
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
87
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:
283
286 void syncTrustedKeys( SyncTrustedKeyBits mode_r = SYNC_BOTH );
291 void importZyppKeyRingTrustedKeys();
295 void exportTrustedKeysInZyppKeyRing();
296
297private:
302
303 using RpmArgVec = std::vector<const char *>;
304
314 void run_rpm( const RpmArgVec& options,
317
318
322 bool systemReadLine(std::string &line);
323
328 int systemStatus();
329
333 void systemKill();
334
339
344 std::string error_message;
345
348
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
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
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
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
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:39
Base class for reference counted objects.
Extract and remember posttrans scripts for later execution.
std::string error_message
Error message from running rpm as external program.
Definition RpmDb.h:344
std::vector< const char * > RpmArgVec
Definition RpmDb.h:303
class InstTargetError Error
Default error class.
Definition RpmDb.h:57
void installPackage(const Pathname &filename, RpmInstFlags flags=RPMINST_NONE)
install rpm package
Definition RpmDb.cc:1652
Pathname _backuppath
/var/adm/backup
Definition RpmDb.h:347
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
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
bool initialized() const
Definition RpmDb.h:125
ExternalProgram * process
The connection to the rpm process.
Definition RpmDb.h:301
SyncTrustedKeyBits
Sync mode for syncTrustedKeys.
Definition RpmDb.h:278
@ SYNC_TO_KEYRING
export rpm trusted keys into zypp trusted keyring
Definition RpmDb.h:279
@ SYNC_FROM_KEYRING
import zypp trusted keys into rpm database.
Definition RpmDb.h:280
int systemStatus()
Return the exit status of the general rpm process, closing the connection if not already done.
Definition RpmDb.cc:1527
std::set< std::string > FileList
Definition RpmDb.h:370
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
void systemKill()
Forcably kill the system process.
Definition RpmDb.cc:1550
const Pathname & root() const
Definition RpmDb.h:109
RpmDb()
Constructor.
Definition RpmDb.cc:228
void removePackage(const std::string &name_r, RpmInstFlags flags=RPMINST_NONE)
remove rpm package
Definition RpmDb.cc:1854
void createPackageBackups(bool yes)
whether to create package backups during install or removal
Definition RpmDb.h:495
const Pathname & dbPath() const
Definition RpmDb.h:117
Pathname _dbPath
Directory that contains the rpmdb.
Definition RpmDb.h:91
bool _packagebackups
create package backups?
Definition RpmDb.h:350
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
Pathname getBackupPath(void)
get backup dir for rpm config files
Definition RpmDb.h:460
Pathname _root
Root directory for all operations.
Definition RpmDb.h:86
int exit_code
The exit code of the rpm process, or -1 if not yet known.
Definition RpmDb.h:338
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
CheckPackageResult
checkPackage result
Definition RpmDb.h:377
bool systemReadLine(std::string &line)
Read a line from the general rpm query.
Definition RpmDb.cc:1474
intrusive_ptr< const RpmHeader > constPtr
Definition RpmHeader.h:65
Subclass to retrieve rpm database content.
Definition librpmDb.h:198
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:412
std::ostream & dumpOn(std::ostream &str, const RpmPostTransCollector &obj)
Easy-to use interface to the ZYPP dependency resolver.
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition Arch.h:247
Detailed rpm signature check log messages A single multiline message if CHK_OK.
Definition RpmDb.h:392
db_const_iterator(const Pathname &root_r, const Pathname &dbPath_r)
Definition RpmDb.h:71