libzypp  17.36.3
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 
34 #include <zypp/ZYppCallbacks.h>
35 
36 namespace zypp
37 {
38 namespace target
39 {
40 class RpmPostTransCollector;
41 namespace rpm
42 {
43 
45 //
46 // CLASS NAME : RpmDb
51 {
52 public:
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  //
81 private:
82 
87 
92 
93 public:
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  //
200 public:
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  //
275 public:
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 
297 private:
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 
368 public:
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 
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 
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 
512 public:
513 
517  std::ostream & dumpOn( std::ostream & str ) const override;
518 
519 protected:
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 
526 std::ostream & operator<<( std::ostream & str, RpmDb::CheckPackageResult obj ) ZYPP_API;
527 
529 std::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
Interface to the rpm program.
Definition: RpmDb.h:50
TraitsType::constPtrType constPtr
Definition: Package.h:39
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:65
db_const_iterator(const Pathname &root_r, const Pathname &dbPath_r)
Definition: RpmDb.h:71
class InstTargetError Error
Default error class.
Definition: RpmDb.h:57
Pathname _root
Root directory for all operations.
Definition: RpmDb.h:86
std::ostream & operator<<(std::ostream &str, const librpmDb::db_const_iterator &obj)
Definition: librpmDb.cc:412
String related utilities and Regular expression matching.
std::vector< const char * > RpmArgVec
Definition: RpmDb.h:303
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
Wrapper providing a librpmDb::db_const_iterator for this RpmDb.
Definition: RpmDb.h:64
Pathname getBackupPath(void)
get backup dir for rpm config files
Definition: RpmDb.h:460
Extract and remember posttrans scripts for later execution.
bool empty() const
Test for an empty path.
Definition: Pathname.h:116
Pathname _backuppath
/var/adm/backup
Definition: RpmDb.h:347
int exit_code
The exit code of the rpm process, or -1 if not yet known.
Definition: RpmDb.h:338
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
Subclass to retrieve rpm database content.
SyncTrustedKeyBits
Sync mode for syncTrustedKeys.
Definition: RpmDb.h:277
const Arch Arch_armv7hnl Arch_armv7nhl ZYPP_API
Definition: ResTraits.h:93
Detailed rpm signature check log messages A single multiline message if CHK_OK.
Definition: RpmDb.h:391
ExternalProgram * process
The connection to the rpm process.
Definition: RpmDb.h:301
Stderr_Disposition
Define symbols for different policies on the handling of stderr.
Base class for reference counted objects.
std::ostream & dumpOn(std::ostream &str, const RpmPostTransCollector &obj)
bool _packagebackups
create package backups?
Definition: RpmDb.h:350
void createPackageBackups(bool yes)
whether to create package backups during install or removal
Definition: RpmDb.h:495
const Pathname & root() const
Definition: RpmDb.h:109
const Pathname & dbPath() const
Definition: RpmDb.h:117
std::string error_message
Error message from running rpm as external program.
Definition: RpmDb.h:344
CheckPackageResult
checkPackage result
Definition: RpmDb.h:376
std::set< std::string > FileList
Definition: RpmDb.h:370
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
bool initialized() const
Definition: RpmDb.h:125
Pathname _dbPath
Directory that contains the rpmdb.
Definition: RpmDb.h:91
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26