libzypp 17.35.11
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>
26
27#include <zypp/Package.h>
28#include <zypp/KeyRing.h>
29
34#include <zypp/ZYppCallbacks.h>
35
36namespace zypp
37{
38namespace target
39{
40class RpmPostTransCollector;
41namespace rpm
42{
43
45//
46// CLASS NAME : RpmDb
51{
52public:
53
57 using Error = class InstTargetError;
58
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,
259
269 void getData( const std::string & name_r, const Edition & ed_r,
271
273 //
275public:
278 {
279 SYNC_TO_KEYRING = 1<<0,
280 SYNC_FROM_KEYRING = 1<<1,
281 SYNC_BOTH = SYNC_TO_KEYRING | SYNC_FROM_KEYRING
282 };
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,
316 ExternalProgram::Stderr_To_Stdout);
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
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
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
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
Subclass to retrieve rpm database content.
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition AutoDispose.h:95
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
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition PublicKey.h:365
Base class for reference counted objects.
bool empty() const
Test for an empty path.
Definition Pathname.h:116
Extract and remember posttrans scripts for later execution.
Interface to the rpm program.
Definition RpmDb.h:51
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
Pathname _backuppath
/var/adm/backup
Definition RpmDb.h:347
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
std::set< std::string > FileList
Definition RpmDb.h:370
const Pathname & root() const
Definition RpmDb.h:109
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
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
CheckPackageResult
checkPackage result
Definition RpmDb.h:377
intrusive_ptr< const RpmHeader > constPtr
Definition RpmHeader.h:65
Manage access to librpm database.
Definition librpmDb.h:52
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:411
Easy-to use interface to the ZYPP dependency resolver.
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
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
Wrapper providing a librpmDb::db_const_iterator for this RpmDb.
Definition RpmDb.h:65
db_const_iterator(const Pathname &root_r, const Pathname &dbPath_r)
Definition RpmDb.h:71