libzypp  11.13.5
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,
437  };
438 
446  checkPackageResult checkPackage( const Pathname & path_r );
447 
458  void installPackage ( const Pathname & filename, RpmInstFlags flags = RPMINST_NONE );
459 
470  void removePackage( const std::string & name_r, RpmInstFlags flags = RPMINST_NONE );
471  void removePackage( Package::constPtr package, RpmInstFlags flags = RPMINST_NONE );
472 
477  Pathname getBackupPath (void)
478  {
479  return _backuppath;
480  }
481 
489  bool backupPackage(const std::string& packageName);
490 
497  bool backupPackage(const Pathname& filename);
498 
504  void setBackupPath(const Pathname& path);
505 
512  void createPackageBackups(bool yes)
513  {
514  _packagebackups = yes;
515  }
516 
527  bool queryChangedFiles(FileList & fileList, const std::string& packageName);
528 
529 public:
530 
534  virtual std::ostream & dumpOn( std::ostream & str ) const;
535 
536 protected:
537  void doRemovePackage( const std::string & name_r, RpmInstFlags flags, callback::SendReport<RpmRemoveReport> & report );
538  void doInstallPackage( const Pathname & filename, RpmInstFlags flags, callback::SendReport<RpmInstallReport> & report );
540 };
541 
542 } // namespace rpm
543 } // namespace target
544 } // namespace zypp
545 
546 #endif // ZYPP_TARGET_RPM_RPMDB_H