libzypp  17.35.8
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 
33 #include <zypp/ZYppCallbacks.h>
34 
35 namespace zypp
36 {
37 namespace target
38 {
39 class RpmPostTransCollector;
40 namespace rpm
41 {
42 
44 //
45 // CLASS NAME : RpmDb
50 {
51 public:
52 
56  using Error = class InstTargetError;
57 
59  //
60  // INITALISATION
61  //
63 private:
64 
69 
74 
75 public:
76 
81  RpmDb();
82 
86  ~RpmDb() override;
87 
91  const Pathname & root() const
92  {
93  return _root;
94  }
95 
99  const Pathname & dbPath() const
100  {
101  return _dbPath;
102  }
103 
107  bool initialized() const
108  {
109  return( ! _root.empty() );
110  }
111 
126  void initDatabase( Pathname root_r = Pathname(), bool doRebuild_r = false );
127 
136  void closeDatabase();
137 
144  void rebuildDatabase();
145 
152  void importPubkey( const PublicKey & pubkey_r );
153 
160  void removePubkey( const PublicKey & pubkey_r );
161 
165  std::list<PublicKey> pubkeys() const;
166 
170  std::set<Edition> pubkeyEditions() const;
171 
173  //
174  // Direct RPM database retrieval via librpm.
175  //
177 public:
178 
184  std::list<FileInfo> fileList( const std::string & name_r, const Edition & edition_r ) const;
185 
190  bool hasFile( const std::string & file_r, const std::string & name_r = "" ) const;
191 
196  std::string whoOwnsFile( const std::string & file_r ) const;
197 
201  bool hasProvides( const std::string & tag_r ) const;
202 
206  bool hasRequiredBy( const std::string & tag_r ) const;
207 
211  bool hasConflicts( const std::string & tag_r ) const;
212 
216  bool hasPackage( const std::string & name_r ) const;
217 
221  bool hasPackage( const std::string & name_r, const Edition & ed_r ) const;
222 
234  void getData( const std::string & name_r,
235  RpmHeader::constPtr & result_r ) const;
236 
246  void getData( const std::string & name_r, const Edition & ed_r,
247  RpmHeader::constPtr & result_r ) const;
248 
250  //
252 public:
255  {
256  SYNC_TO_KEYRING = 1<<0,
257  SYNC_FROM_KEYRING = 1<<1,
258  SYNC_BOTH = SYNC_TO_KEYRING | SYNC_FROM_KEYRING
259  };
263  void syncTrustedKeys( SyncTrustedKeyBits mode_r = SYNC_BOTH );
268  void importZyppKeyRingTrustedKeys();
272  void exportTrustedKeysInZyppKeyRing();
273 
274 private:
279 
280  using RpmArgVec = std::vector<const char *>;
281 
291  void run_rpm( const RpmArgVec& options,
294 
295 
299  bool systemReadLine(std::string &line);
300 
305  int systemStatus();
306 
310  void systemKill();
311 
316 
321  std::string error_message;
322 
325 
328 
338  void processConfigFiles(const std::string& line,
339  const std::string& name,
340  const char* typemsg,
341  const char* difffailmsg,
342  const char* diffgenmsg);
343 
344 
345 public:
346 
347  using FileList = std::set<std::string>;
348 
354  {
355  CHK_OK = 0,
356  CHK_NOTFOUND = 1,
357  CHK_FAIL = 2,
358  CHK_NOTTRUSTED = 3,
359  CHK_NOKEY = 4,
360  CHK_ERROR = 5,
361  CHK_NOSIG = 6,
362  };
363 
368  struct CheckPackageDetail : std::vector<std::pair<CheckPackageResult,std::string>>
369  {};
370 
381  CheckPackageResult checkPackage( const Pathname & path_r, CheckPackageDetail & detail_r );
383  CheckPackageResult checkPackage( const Pathname & path_r );
384 
395  CheckPackageResult checkPackageSignature( const Pathname & path_r, CheckPackageDetail & detail_r );
396 
407  void installPackage ( const Pathname & filename, RpmInstFlags flags = RPMINST_NONE );
409  void installPackage( const Pathname & filename, RpmInstFlags flags, RpmPostTransCollector* postTransCollector_r );
410 
421  void removePackage( const std::string & name_r, RpmInstFlags flags = RPMINST_NONE );
422  void removePackage( Package::constPtr package, RpmInstFlags flags = RPMINST_NONE );
424  void removePackage( const std::string & name_r, RpmInstFlags flags, RpmPostTransCollector* postTransCollector_r );
425  void removePackage( const Package::constPtr& package, RpmInstFlags flags, RpmPostTransCollector* postTransCollector_r );
426 
431  int runposttrans( const Pathname & filename_r, const std::function<void(const std::string&)>& output_r );
432 
438  {
439  return _backuppath;
440  }
441 
449  bool backupPackage(const std::string& packageName);
450 
457  bool backupPackage(const Pathname& filename);
458 
464  void setBackupPath(const Pathname& path);
465 
472  void createPackageBackups(bool yes)
473  {
474  _packagebackups = yes;
475  }
476 
487  bool queryChangedFiles(FileList & fileList, const std::string& packageName);
488 
489 public:
490 
494  std::ostream & dumpOn( std::ostream & str ) const override;
495 
496 protected:
497  void doRemovePackage( const std::string & name_r, RpmInstFlags flags, RpmPostTransCollector* postTransCollector_r, callback::SendReport<RpmRemoveReport> & report );
498  void doInstallPackage( const Pathname & filename, RpmInstFlags flags, RpmPostTransCollector* postTransCollector_r, callback::SendReport<RpmInstallReport> & report );
499  void doRebuildDatabase(callback::SendReport<RebuildDBReport> & report);
500 };
501 
503 std::ostream & operator<<( std::ostream & str, RpmDb::CheckPackageResult obj ) ZYPP_API;
504 
506 std::ostream & operator<<( std::ostream & str, const RpmDb::CheckPackageDetail & obj ) ZYPP_API;
507 
508 } // namespace rpm
509 } // namespace target
510 } // namespace zypp
511 
512 #endif // ZYPP_TARGET_RPM_RPMDB_H
Interface to the rpm program.
Definition: RpmDb.h:49
TraitsType::constPtrType constPtr
Definition: Package.h:39
intrusive_ptr< const RpmHeader > constPtr
Definition: RpmHeader.h:65
class InstTargetError Error
Default error class.
Definition: RpmDb.h:56
Pathname _root
Root directory for all operations.
Definition: RpmDb.h:68
std::ostream & operator<<(std::ostream &str, const librpmDb::db_const_iterator &obj)
Definition: librpmDb.cc:705
String related utilities and Regular expression matching.
std::vector< const char * > RpmArgVec
Definition: RpmDb.h:280
Edition represents [epoch:]version[-release]
Definition: Edition.h:60
Pathname getBackupPath(void)
get backup dir for rpm config files
Definition: RpmDb.h:437
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:324
int exit_code
The exit code of the rpm process, or -1 if not yet known.
Definition: RpmDb.h:315
Execute a program and give access to its io An object of this class encapsulates the execution of an ...
SyncTrustedKeyBits
Sync mode for syncTrustedKeys.
Definition: RpmDb.h:254
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:368
ExternalProgram * process
The connection to the rpm process.
Definition: RpmDb.h:278
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:327
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:364
void createPackageBackups(bool yes)
whether to create package backups during install or removal
Definition: RpmDb.h:472
const Pathname & root() const
Definition: RpmDb.h:91
const Pathname & dbPath() const
Definition: RpmDb.h:99
std::string error_message
Error message from running rpm as external program.
Definition: RpmDb.h:321
CheckPackageResult
checkPackage result
Definition: RpmDb.h:353
std::set< std::string > FileList
Definition: RpmDb.h:347
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
bool initialized() const
Definition: RpmDb.h:107
Pathname _dbPath
Directory that contains the rpmdb.
Definition: RpmDb.h:73
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26