Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / target / rpm / RpmDb.h
index 5ae6918..f2766c1 100644 (file)
@@ -26,6 +26,7 @@
 #include "zypp/Package.h"
 #include "zypp/KeyRing.h"
 
+#include "zypp/target/rpm/RpmFlags.h"
 #include "zypp/target/rpm/RpmHeader.h"
 #include "zypp/target/rpm/RpmCallbacks.h"
 #include "zypp/ZYppCallbacks.h"
@@ -187,11 +188,15 @@ public:
    * (no packages were installed or deleted). Otherwise the new database
    * is kept, and the old one is removed.
    *
+   * If the  database alredy exists and \c doRebuild_r is true, \ref rebuildDatabase
+   * is called.
+   *
    * \throws RpmException
    *
    **/
   void initDatabase( Pathname root_r = Pathname(),
-                     Pathname dbPath_r = Pathname() );
+                     Pathname dbPath_r = Pathname(),
+                     bool doRebuild_r = false );
 
   /**
    * Block further access to the rpm database and go back to uninitialized
@@ -220,6 +225,14 @@ public:
   void importPubkey( const PublicKey & pubkey_r );
 
   /**
+   * Remove a public key from the rpm database
+   *
+   * \throws RpmException
+   *
+   **/
+  void removePubkey( const PublicKey & pubkey_r );
+
+  /**
    * Return the long ids of all installed public keys.
    **/
   std::list<PublicKey> pubkeys() const;
@@ -231,33 +244,6 @@ public:
 
   ///////////////////////////////////////////////////////////////////
   //
-  // Cached RPM database retrieval via librpm.
-  //
-  ///////////////////////////////////////////////////////////////////
-private:
-
-  class Packages;
-
-  Packages & _packages;
-
-  std::set<std::string> _filerequires;
-
-public:
-
-  /**
-   * @return Whether the list of installed packages is valid, or
-   * you'd better reread it. (<B>NOTE:</B> returns valid, if not
-   * initialized).
-   **/
-  bool packagesValid() const;
-
-  /**
-   * If necessary build, and return the list of all installed packages.
-   **/
-  const std::list<Package::Ptr> & getPackages();
-
-  ///////////////////////////////////////////////////////////////////
-  //
   // Direct RPM database retrieval via librpm.
   //
   ///////////////////////////////////////////////////////////////////
@@ -333,20 +319,21 @@ public:
   void getData( const std::string & name_r, const Edition & ed_r,
                 RpmHeader::constPtr & result_r ) const;
 
-
-  /**
-   * Create a package from RpmHeader
-   * return NULL on error
-   **/
-
-  static Package::Ptr makePackageFromHeader( const RpmHeader::constPtr header,
-                                             std::set<std::string> * filerequires,
-                                             const Pathname & location, Repository repo );
-
   ///////////////////////////////////////////////////////////////////
   //
   ///////////////////////////////////////////////////////////////////
 public:
+  /** Sync mode for \ref syncTrustedKeys */
+  enum SyncTrustedKeyBits
+  {
+    SYNC_TO_KEYRING    = 1<<0, //! export rpm trusted keys into zypp trusted keyring
+    SYNC_FROM_KEYRING  = 1<<1, //! import zypp trusted keys into rpm database.
+    SYNC_BOTH          = SYNC_TO_KEYRING | SYNC_FROM_KEYRING
+  };
+  /**
+   * Sync trusted keys stored in rpm database and zypp trusted keyring.
+   */
+  void syncTrustedKeys( SyncTrustedKeyBits mode_r = SYNC_BOTH );
   /**
    * iterates through zypp keyring and import all non existant keys
    * into rpm keyring
@@ -356,6 +343,7 @@ public:
    * insert all rpm trusted keys into zypp trusted keyring
    */
   void exportTrustedKeysInZyppKeyRing();
+
 private:
   /**
    * The connection to the rpm process.
@@ -399,6 +387,12 @@ private:
   */
   int exit_code;
 
+  /**
+   * Error message from running rpm as external program.
+   * Use only if something fail.
+   */
+  std::string error_message;
+
   /** /var/adm/backup */
   Pathname _backuppath;
 
@@ -429,31 +423,10 @@ public:
   typedef std::set<std::string> FileList;
 
   /**
-   * Bits representing rpm installation options, useable as or
-   * combination
-   *
-   * @see installPackage(), removePackage()
-   * */
-  enum RpmInstFlag
-  {
-    RPMINST_NONE       = 0x0000,
-    RPMINST_NODOCS     = 0x0001,
-    RPMINST_NOSCRIPTS  = 0x0002,
-    RPMINST_FORCE      = 0x0004,
-    RPMINST_NODEPS     = 0x0008,
-    RPMINST_IGNORESIZE = 0x0010,
-    RPMINST_JUSTDB     = 0x0020,
-    RPMINST_NODIGEST   = 0x0040,
-    RPMINST_NOSIGNATURE= 0x0080,
-    RPMINST_NOUPGRADE  = 0x0100,
-    RPMINST_TEST        = 0x0200
-  };
-
-  /**
    * checkPackage result
    * @see checkPackage
    * */
-  enum checkPackageResult
+  enum CheckPackageResult
   {
     CHK_OK            = 0, /*!< Signature is OK. */
     CHK_NOTFOUND      = 1, /*!< Signature is unknown type. */
@@ -463,14 +436,24 @@ public:
     CHK_ERROR         = 5  /*!< File does not exist or can't be opened. */
   };
 
+  /** Detailed rpm signature check log messages
+   * A single multiline message if \ref CHK_OK. Otherwise each message line
+   * together with it's \ref CheckPackageResult.
+   */
+  struct CheckPackageDetail : std::vector<std::pair<CheckPackageResult,std::string>>
+  {};
+
   /**
    * Check signature of rpm file on disk.
    *
-   * @param filename which file to check
+   * @param path_r which file to check
+   * @param detail_r Return detailed rpm log messages
    *
-   * @return checkPackageResult
+   * @return CheckPackageResult
   */
-  checkPackageResult checkPackage( const Pathname & path_r );
+  CheckPackageResult checkPackage( const Pathname & path_r, CheckPackageDetail & detail_r );
+  /** \overload Ignoring the \a datails_r */
+  CheckPackageResult checkPackage( const Pathname & path_r );
 
   /** install rpm package
    *
@@ -482,7 +465,7 @@ public:
    * \throws RpmException
    *
    * */
-  void installPackage (const Pathname& filename, unsigned flags = 0 );
+  void installPackage ( const Pathname & filename, RpmInstFlags flags = RPMINST_NONE );
 
   /** remove rpm package
    *
@@ -494,8 +477,8 @@ public:
    * \throws RpmException
    *
    * */
-  void removePackage(const std::string & name_r, unsigned flags = 0);
-  void removePackage(Package::constPtr package, unsigned flags = 0);
+  void removePackage( const std::string & name_r, RpmInstFlags flags = RPMINST_NONE );
+  void removePackage( Package::constPtr package, RpmInstFlags flags = RPMINST_NONE );
 
   /**
    * get backup dir for rpm config files
@@ -561,13 +544,16 @@ public:
   virtual std::ostream & dumpOn( std::ostream & str ) const;
 
 protected:
-  void doRemovePackage( const std::string & name_r, unsigned flags, callback::SendReport<RpmRemoveReport> & report );
-  void doInstallPackage( const Pathname & filename, unsigned flags, callback::SendReport<RpmInstallReport> & report );
-  const std::list<Package::Ptr> & doGetPackages(callback::SendReport<ScanDBReport> & report);
+  void doRemovePackage( const std::string & name_r, RpmInstFlags flags, callback::SendReport<RpmRemoveReport> & report );
+  void doInstallPackage( const Pathname & filename, RpmInstFlags flags, callback::SendReport<RpmInstallReport> & report );
   void doRebuildDatabase(callback::SendReport<RebuildDBReport> & report);
+};
 
+/** \relates RpmDb::CheckPackageResult Stream output */
+std::ostream & operator<<( std::ostream & str, RpmDb::CheckPackageResult obj );
 
-};
+/** \relates RpmDb::checkPackageDetail Stream output */
+std::ostream & operator<<( std::ostream & str, const RpmDb::CheckPackageDetail & obj );
 
 } // namespace rpm
 } // namespace target