libzypp  17.14.0
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 
32 #include "zypp/ZYppCallbacks.h"
33 
34 namespace zypp
35 {
36 namespace target
37 {
38 namespace rpm
39 {
40 
42 //
43 // CLASS NAME : RpmDb
48 {
49 public:
50 
54  typedef class InstTargetError Error;
55 
57  //
58  // INITALISATION
59  //
61 private:
62 
64  DbSI_NO_INIT = 0x0000,
65  DbSI_HAVE_V4 = 0x0001,
66  DbSI_MADE_V4 = 0x0002,
67  DbSI_MODIFIED_V4 = 0x0004,
68  DbSI_HAVE_V3 = 0x0008,
69  DbSI_HAVE_V3TOV4 = 0x0010,
71  };
72 
73  friend std::ostream & operator<<( std::ostream & str, const DbStateInfoBits & obj );
74 
75  void dbsi_set( DbStateInfoBits & val_r, const unsigned & bits_r ) const
76  {
77  val_r = (DbStateInfoBits)(val_r | bits_r);
78  }
79  void dbsi_clr( DbStateInfoBits & val_r, const unsigned & bits_r ) const
80  {
81  val_r = (DbStateInfoBits)(val_r & ~bits_r);
82  }
83  bool dbsi_has( const DbStateInfoBits & val_r, const unsigned & bits_r ) const
84  {
85  return( (val_r & bits_r) == bits_r );
86  }
87 
92 
96  Pathname _root;
97 
101  Pathname _dbPath;
102 
109  void internal_initDatabase( const Pathname & root_r, const Pathname & dbPath_r,
110  DbStateInfoBits & info_r );
111 
116  static void removeV4( const Pathname & dbdir_r, bool v3backup_r );
117 
122  static void removeV3( const Pathname & dbdir_r, bool v3backup_r );
123 
128  void modifyDatabase();
129 
130 public:
131 
136  RpmDb();
137 
141  ~RpmDb();
142 
146  Date timestamp() const;
147 
151  const Pathname & root() const
152  {
153  return _root;
154  }
155 
159  const Pathname & dbPath() const
160  {
161  return _dbPath;
162  }
163 
167  bool initialized() const
168  {
169  return( ! _root.empty() );
170  }
171 
197  void initDatabase( Pathname root_r = Pathname(),
198  Pathname dbPath_r = Pathname(),
199  bool doRebuild_r = false );
200 
209  void closeDatabase();
210 
217  void rebuildDatabase();
218 
225  void importPubkey( const PublicKey & pubkey_r );
226 
233  void removePubkey( const PublicKey & pubkey_r );
234 
238  std::list<PublicKey> pubkeys() const;
239 
243  std::set<Edition> pubkeyEditions() const;
244 
246  //
247  // Direct RPM database retrieval via librpm.
248  //
250 public:
251 
257  std::list<FileInfo> fileList( const std::string & name_r, const Edition & edition_r ) const;
258 
263  bool hasFile( const std::string & file_r, const std::string & name_r = "" ) const;
264 
269  std::string whoOwnsFile( const std::string & file_r ) const;
270 
274  bool hasProvides( const std::string & tag_r ) const;
275 
279  bool hasRequiredBy( const std::string & tag_r ) const;
280 
284  bool hasConflicts( const std::string & tag_r ) const;
285 
289  bool hasPackage( const std::string & name_r ) const;
290 
294  bool hasPackage( const std::string & name_r, const Edition & ed_r ) const;
295 
307  void getData( const std::string & name_r,
308  RpmHeader::constPtr & result_r ) const;
309 
319  void getData( const std::string & name_r, const Edition & ed_r,
320  RpmHeader::constPtr & result_r ) const;
321 
323  //
325 public:
328  {
332  };
346 
347 private:
352 
353  typedef std::vector<const char*> RpmArgVec;
354 
364  void run_rpm( const RpmArgVec& options,
367 
368 
372  bool systemReadLine(std::string &line);
373 
378  int systemStatus();
379 
383  void systemKill();
384 
389 
394  std::string error_message;
395 
397  Pathname _backuppath;
398 
401 
404 
414  void processConfigFiles(const std::string& line,
415  const std::string& name,
416  const char* typemsg,
417  const char* difffailmsg,
418  const char* diffgenmsg);
419 
420 
421 public:
422 
423  typedef std::set<std::string> FileList;
424 
430  {
431  CHK_OK = 0,
433  CHK_FAIL = 2,
435  CHK_NOKEY = 4,
436  CHK_ERROR = 5,
437  CHK_NOSIG = 6,
438  };
439 
444  struct CheckPackageDetail : std::vector<std::pair<CheckPackageResult,std::string>>
445  {};
446 
457  CheckPackageResult checkPackage( const Pathname & path_r, CheckPackageDetail & detail_r );
459  CheckPackageResult checkPackage( const Pathname & path_r );
460 
471  CheckPackageResult checkPackageSignature( const Pathname & path_r, CheckPackageDetail & detail_r );
472 
483  void installPackage ( const Pathname & filename, RpmInstFlags flags = RPMINST_NONE );
484 
495  void removePackage( const std::string & name_r, RpmInstFlags flags = RPMINST_NONE );
496  void removePackage( Package::constPtr package, RpmInstFlags flags = RPMINST_NONE );
497 
502  Pathname getBackupPath (void)
503  {
504  return _backuppath;
505  }
506 
514  bool backupPackage(const std::string& packageName);
515 
522  bool backupPackage(const Pathname& filename);
523 
529  void setBackupPath(const Pathname& path);
530 
537  void createPackageBackups(bool yes)
538  {
539  _packagebackups = yes;
540  }
541 
552  bool queryChangedFiles(FileList & fileList, const std::string& packageName);
553 
554 public:
555 
559  virtual std::ostream & dumpOn( std::ostream & str ) const;
560 
561 protected:
562  void doRemovePackage( const std::string & name_r, RpmInstFlags flags, callback::SendReport<RpmRemoveReport> & report );
563  void doInstallPackage( const Pathname & filename, RpmInstFlags flags, callback::SendReport<RpmInstallReport> & report );
565 };
566 
568 std::ostream & operator<<( std::ostream & str, RpmDb::CheckPackageResult obj );
569 
571 std::ostream & operator<<( std::ostream & str, const RpmDb::CheckPackageDetail & obj );
572 
573 } // namespace rpm
574 } // namespace target
575 } // namespace zypp
576 
577 #endif // ZYPP_TARGET_RPM_RPMDB_H