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

libzypp 17.25.10

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
29 #include <zypp/target/rpm/RpmFlags.h>
30 #include <zypp/target/rpm/RpmHeader.h>
31 #include <zypp/target/rpm/RpmCallbacks.h>
32 #include <zypp/ZYppCallbacks.h>
33
34 namespace zypp
35 {
36 namespace target
37 {
38 namespace rpm
39 {
40
42 //
43 // CLASS NAME : RpmDb
47 class RpmDb : public base::ReferenceCounted, private base::NonCopyable
48 {
49 public:
50
54 typedef class InstTargetError Error;
55
57 //
58 // INITALISATION
59 //
61 private:
62
66 Pathname _root;
67
71 Pathname _dbPath;
72
73 public:
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 //
175 public:
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 //
250 public:
252 enum SyncTrustedKeyBits
253 {
254 SYNC_TO_KEYRING = 1<<0,
255 SYNC_FROM_KEYRING = 1<<1,
256 SYNC_BOTH = SYNC_TO_KEYRING | SYNC_FROM_KEYRING
257 };
261 void syncTrustedKeys( SyncTrustedKeyBits mode_r = SYNC_BOTH );
266 void importZyppKeyRingTrustedKeys();
270 void exportTrustedKeysInZyppKeyRing();
271
272 private:
276 ExternalProgram *process;
277
278 typedef std::vector<const char*> RpmArgVec;
279
289 void run_rpm( const RpmArgVec& options,
290 ExternalProgram::Stderr_Disposition stderr_disp =
291 ExternalProgram::Stderr_To_Stdout);
292
293
297 bool systemReadLine(std::string &line);
298
303 int systemStatus();
304
308 void systemKill();
309
313 int exit_code;
314
319 std::string error_message;
320
322 Pathname _backuppath;
323
325 bool _packagebackups;
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
343 public:
344
345 typedef std::set<std::string> FileList;
346
351 enum CheckPackageResult
352 {
353 CHK_OK = 0,
354 CHK_NOTFOUND = 1,
355 CHK_FAIL = 2,
356 CHK_NOTTRUSTED = 3,
357 CHK_NOKEY = 4,
358 CHK_ERROR = 5,
359 CHK_NOSIG = 6,
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
393 CheckPackageResult checkPackageSignature( const Pathname & path_r, CheckPackageDetail & detail_r );
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
424 Pathname getBackupPath (void)
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
476 public:
477
481 virtual std::ostream & dumpOn( std::ostream & str ) const;
482
483 protected:
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 );
486 void doRebuildDatabase(callback::SendReport<RebuildDBReport> & report);
487 };
488
490 std::ostream & operator<<( std::ostream & str, RpmDb::CheckPackageResult obj );
491
493 std::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
ExternalProgram.h
KeyRing.h
report
callback::SendReport< DownloadProgressReport > * report
Definition: MediaCurl.cc:70
Package.h
Pathname.h
RpmCallbacks.h
RpmFlags.h
RpmHeader.h
ZYppCallbacks.h
zypp::Edition
Edition represents [epoch:]version[-release]
Definition: Edition.h:61
zypp::ExternalProgram
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
Definition: ExternalProgram.h:60
zypp::ExternalProgram::Stderr_Disposition
Stderr_Disposition
Define symbols for different policies on the handling of stderr.
Definition: ExternalProgram.h:70
zypp::ExternalProgram::Stderr_To_Stdout
@ Stderr_To_Stdout
Definition: ExternalProgram.h:73
zypp::Package::constPtr
TraitsType::constPtrType constPtr
Definition: Package.h:38
zypp::PublicKey
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:276
zypp::base::ReferenceCounted
Base class for reference counted objects.
Definition: ReferenceCounted.h:34
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:45
zypp::filesystem::Pathname::empty
bool empty() const
Test for an empty path.
Definition: Pathname.h:114
zypp::target::rpm::RpmDb
Interface to the rpm program.
Definition: RpmDb.h:48
zypp::target::rpm::RpmDb::getData
void getData(const std::string &name_r, RpmHeader::constPtr &result_r) const
Get an installed packages data from rpmdb.
Definition: RpmDb.cc:1079
zypp::target::rpm::RpmDb::doRebuildDatabase
void doRebuildDatabase(callback::SendReport< RebuildDBReport > &report)
Definition: RpmDb.cc:400
zypp::target::rpm::RpmDb::queryChangedFiles
bool queryChangedFiles(FileList &fileList, const std::string &packageName)
determine which files of an installed package have been modified.
Definition: RpmDb.cc:1279
zypp::target::rpm::RpmDb::error_message
std::string error_message
Error message from running rpm as external program.
Definition: RpmDb.h:319
zypp::target::rpm::RpmDb::hasRequiredBy
bool hasRequiredBy(const std::string &tag_r) const
Return true if at least one package requires a certain tag.
Definition: RpmDb.cc:1023
zypp::target::rpm::RpmDb::dumpOn
virtual std::ostream & dumpOn(std::ostream &str) const
Dump debug info.
Definition: RpmDb.cc:253
zypp::target::rpm::RpmDb::whoOwnsFile
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:991
zypp::target::rpm::RpmDb::exportTrustedKeysInZyppKeyRing
void exportTrustedKeysInZyppKeyRing()
insert all rpm trusted keys into zypp trusted keyring
Definition: RpmDb.cc:685
zypp::target::rpm::RpmDb::importPubkey
void importPubkey(const PublicKey &pubkey_r)
Import ascii armored public key in file pubkey_r.
Definition: RpmDb.cc:694
zypp::target::rpm::RpmDb::installPackage
void installPackage(const Pathname &filename, RpmInstFlags flags=RPMINST_NONE)
install rpm package
Definition: RpmDb.cc:1571
zypp::target::rpm::RpmDb::_backuppath
Pathname _backuppath
/var/adm/backup
Definition: RpmDb.h:322
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:1345
zypp::target::rpm::RpmDb::initDatabase
void initDatabase(Pathname root_r=Pathname(), bool doRebuild_r=false)
Prepare access to the rpm database below root_r.
Definition: RpmDb.cc:264
zypp::target::rpm::RpmDb::initialized
bool initialized() const
Definition: RpmDb.h:105
zypp::target::rpm::RpmDb::process
ExternalProgram * process
The connection to the rpm process.
Definition: RpmDb.h:276
zypp::target::rpm::RpmDb::SyncTrustedKeyBits
SyncTrustedKeyBits
Sync mode for syncTrustedKeys.
Definition: RpmDb.h:253
zypp::target::rpm::RpmDb::SYNC_TO_KEYRING
@ SYNC_TO_KEYRING
export rpm trusted keys into zypp trusted keyring
Definition: RpmDb.h:254
zypp::target::rpm::RpmDb::SYNC_FROM_KEYRING
@ SYNC_FROM_KEYRING
import zypp trusted keys into rpm database.
Definition: RpmDb.h:255
zypp::target::rpm::RpmDb::SYNC_BOTH
@ SYNC_BOTH
Definition: RpmDb.h:256
zypp::target::rpm::RpmDb::pubkeys
std::list< PublicKey > pubkeys() const
Return the long ids of all installed public keys.
Definition: RpmDb.cc:874
zypp::target::rpm::RpmDb::pubkeyEditions
std::set< Edition > pubkeyEditions() const
Return the edition of all installed public keys.
Definition: RpmDb.cc:912
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:1444
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:1273
zypp::target::rpm::RpmDb::backupPackage
bool backupPackage(const std::string &packageName)
create tar.gz of all changed files in a Package
Definition: RpmDb.cc:1922
zypp::target::rpm::RpmDb::hasProvides
bool hasProvides(const std::string &tag_r) const
Return true if at least one package provides a certain tag.
Definition: RpmDb.cc:1009
zypp::target::rpm::RpmDb::systemKill
void systemKill()
Forcably kill the system process.
Definition: RpmDb.cc:1467
zypp::target::rpm::RpmDb::removePubkey
void removePubkey(const PublicKey &pubkey_r)
Remove a public key from the rpm database.
Definition: RpmDb.cc:807
zypp::target::rpm::RpmDb::RpmDb
RpmDb()
Constructor.
Definition: RpmDb.cc:219
zypp::target::rpm::RpmDb::removePackage
void removePackage(const std::string &name_r, RpmInstFlags flags=RPMINST_NONE)
remove rpm package
Definition: RpmDb.cc:1766
zypp::target::rpm::RpmDb::doInstallPackage
void doInstallPackage(const Pathname &filename, RpmInstFlags flags, callback::SendReport< RpmInstallReport > &report)
Definition: RpmDb.cc:1601
zypp::target::rpm::RpmDb::createPackageBackups
void createPackageBackups(bool yes)
whether to create package backups during install or removal
Definition: RpmDb.h:459
zypp::target::rpm::RpmDb::fileList
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:936
zypp::target::rpm::RpmDb::_dbPath
Pathname _dbPath
Directory that contains the rpmdb.
Definition: RpmDb.h:71
zypp::target::rpm::RpmDb::closeDatabase
void closeDatabase()
Block further access to the rpm database and go back to uninitialized state.
Definition: RpmDb.cc:354
zypp::target::rpm::RpmDb::setBackupPath
void setBackupPath(const Pathname &path)
set path where package backups are stored
Definition: RpmDb.cc:2049
zypp::target::rpm::RpmDb::doRemovePackage
void doRemovePackage(const std::string &name_r, RpmInstFlags flags, callback::SendReport< RpmRemoveReport > &report)
Definition: RpmDb.cc:1797
zypp::target::rpm::RpmDb::_packagebackups
bool _packagebackups
create package backups?
Definition: RpmDb.h:325
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:1267
zypp::target::rpm::RpmDb::importZyppKeyRingTrustedKeys
void importZyppKeyRingTrustedKeys()
iterates through zypp keyring and import all non existant keys into rpm keyring
Definition: RpmDb.cc:682
zypp::target::rpm::RpmDb::getBackupPath
Pathname getBackupPath(void)
get backup dir for rpm config files
Definition: RpmDb.h:424
zypp::target::rpm::RpmDb::_root
Pathname _root
Root directory for all operations.
Definition: RpmDb.h:66
zypp::target::rpm::RpmDb::Error
class InstTargetError Error
Default error class.
Definition: RpmDb.h:54
zypp::target::rpm::RpmDb::hasConflicts
bool hasConflicts(const std::string &tag_r) const
Return true if at least one package conflicts with a certain tag.
Definition: RpmDb.cc:1037
zypp::target::rpm::RpmDb::dbPath
const Pathname & dbPath() const
Definition: RpmDb.h:97
zypp::target::rpm::RpmDb::RpmArgVec
std::vector< const char * > RpmArgVec
Definition: RpmDb.h:278
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:313
zypp::target::rpm::RpmDb::syncTrustedKeys
void syncTrustedKeys(SyncTrustedKeyBits mode_r=SYNC_BOTH)
Sync trusted keys stored in rpm database and zypp trusted keyring.
Definition: RpmDb.cc:581
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:1474
zypp::target::rpm::RpmDb::root
const Pathname & root() const
Definition: RpmDb.h:89
zypp::target::rpm::RpmDb::CheckPackageResult
CheckPackageResult
checkPackage result
Definition: RpmDb.h:352
zypp::target::rpm::RpmDb::CHK_ERROR
@ CHK_ERROR
Definition: RpmDb.h:358
zypp::target::rpm::RpmDb::CHK_NOTTRUSTED
@ CHK_NOTTRUSTED
Definition: RpmDb.h:356
zypp::target::rpm::RpmDb::CHK_NOSIG
@ CHK_NOSIG
Definition: RpmDb.h:359
zypp::target::rpm::RpmDb::CHK_NOKEY
@ CHK_NOKEY
Definition: RpmDb.h:357
zypp::target::rpm::RpmDb::CHK_FAIL
@ CHK_FAIL
Definition: RpmDb.h:355
zypp::target::rpm::RpmDb::CHK_NOTFOUND
@ CHK_NOTFOUND
Definition: RpmDb.h:354
zypp::target::rpm::RpmDb::CHK_OK
@ CHK_OK
Definition: RpmDb.h:353
zypp::target::rpm::RpmDb::~RpmDb
~RpmDb()
Destructor.
Definition: RpmDb.cc:238
zypp::target::rpm::RpmDb::hasPackage
bool hasPackage(const std::string &name_r) const
Return true if package is installed.
Definition: RpmDb.cc:1051
zypp::target::rpm::RpmDb::FileList
std::set< std::string > FileList
Definition: RpmDb.h:345
zypp::target::rpm::RpmDb::systemReadLine
bool systemReadLine(std::string &line)
Read a line from the general rpm query.
Definition: RpmDb.cc:1392
zypp::target::rpm::RpmDb::rebuildDatabase
void rebuildDatabase()
Rebuild the rpm database (rpm –rebuilddb).
Definition: RpmDb.cc:382
zypp::target::rpm::RpmDb::hasFile
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:965
zypp::target::rpm::RpmHeader::constPtr
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:64
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::RPMINST_NONE
@ RPMINST_NONE
Definition: RpmFlags.h:39
zypp::target::rpm::operator<<
std::ostream & operator<<(std::ostream &str, const librpmDb::db_const_iterator &obj)
Definition: librpmDb.cc:706
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
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:367