Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / Resolver.h
index 5604f48..aaeffbe 100644 (file)
 #include "zypp/base/PtrTypes.h"
 
 #include "zypp/ResPool.h"
-#include "zypp/UpgradeStatistics.h"
-#include "zypp/solver/detail/Resolver.h"
-#include "zypp/solver/detail/ResolverContext.h"
+#include "zypp/PoolItem.h"
+#include "zypp/Capabilities.h"
+#include "zypp/Capability.h"
+
+#include "zypp/solver/detail/Types.h"
+
 #include "zypp/ProblemTypes.h"
+#include "zypp/ResolverProblem.h"
+#include "zypp/ProblemSolution.h"
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
 
-
+  namespace sat
+  {
+    class Transaction;
+  }
 
   ///////////////////////////////////////////////////////////////////
   //
   //   CLASS NAME : Resolver
   //
-  /** Resolver interface.
-  */
+  /**
+   * Dependency resolver interface.
+   *
+   * To resolve dependencies after making changes to the \ref ResPool (using
+   * \ref addRequire(), \ref addConflict(), \ref applySolutions(), or by making
+   * the changes directly on the \ref PoolItem status objects,
+   * call the \ref resolvePool() method.
+   */
   class Resolver : public base::ReferenceCounted, private base::NonCopyable
   {
   public:
@@ -48,90 +62,96 @@ namespace zypp
     /**
      * Resolve package dependencies:
      *
-     * Verify consistency of system
+     * Enter \ref systemVerification mode to monitor and repair dependencies
+     * of already installed packages, and solve immediately.
      *
+     * Call \ref setSystemVerification to turn of this mode.
      **/
-    bool verifySystem (void);
+    bool verifySystem();
 
-    /**
-     * Establish state of 'higher level' Resolvables in Pool
-     *
-     * Must be called when dealing with non-package resolvables,
-     * like Patches, Patterns, and Products
-     *
-     * Must be called with a 'plain' pool, e.g. no additonal
-     * transacts set.
-     *
-     * return true if it was successful
-     * return false if not (this will only happen if other
-     *   transactions are in the pool which will lead to
-     *   no solution)
-     **/
-    bool establishPool (void);
 
     /**
-     * go through all package 'freshen' dependencies and
-     * schedule matches for installation.
+     * Resolve package dependencies:
      *
-     * To be called at begin of installation and upgrade.
-     * Probably also useful after adding a new package
-     * repository.
+     * Try to execute all pending transactions (there may be more than
+     * one!).
+     * The solver collects all transactions (install/delete resolvables)
+     * from the pool, generates task, solving it and writes the
+     * results back to pool
      *
-     * return true if it was successful
-     * return false if not (this will only happen if other
-     *   transactions are in the pool which will lead to
-     *   no solution)
+     * Returns "true" on success (i.e., if there were no problems that
+     * need user interaction) and "false" if there were problems.  In
+     * the latter case, use problems() and later applySolutions()
+     * below.
      **/
-    bool freshenPool (void);
+    bool resolvePool();
+
 
     /**
      * Resolve package dependencies:
      *
-     * Try to execute all pending transactions (there may be more than
-     * one!).
+     * The solver works off the given queue and writes back the solution
+     * to pool.
      *
      * Returns "true" on success (i.e., if there were no problems that
      * need user interaction) and "false" if there were problems.  In
      * the latter case, use problems() and later applySolutions()
      * below.
+     * The solution could be that the solver remove/add some entries
+     * in the task queue. So make a new call of resolveQueue after you
+     * have applied any solution AND check the parameter "queue" if
+     * there has been any changes by the solver and adapt these changes
+     * to e.g. the selectables.
+     *
      **/
-    bool resolvePool (void);
+    bool resolveQueue( solver::detail::SolverQueueItemList & queue );
 
     /*
      * Undo solver changes done in resolvePool()
      * Throwing away all ignored dependencies.
      */
-    void undo( void );
+    void undo();
 
     /*
-     * Get the most recent resolver context
-     *
-     * It will be NULL if resolvePool() or establishPool() was never called.
-     * Depending on the return code of the last resolvePool() call,
-     * it _either_ points to a valid or an invalid solution.
+     * Resets solver information and verify option.
      */
-    solver::detail::ResolverContext_Ptr context (void) const;
+    void reset();
+
 
     /**
-     * Do an distribution upgrade
+     * Do an distribution upgrade (DUP)
      *
-     * This will run a full upgrade on the pool, taking all upgrade
-     * dependencies (provide/obsolete for package renames, split-
-     * provides, etc.) into account and actually removing installed
-     * packages if no upgrade exists.
+     * Perform a distribution upgrade. This performs an update of
+     * all packages with a special resolver algorithm which takes
+     * care of package splits, pattern  and  product  updates,
+     * etc.
+     * This call also turns the solver into \ref upgradeMode, so
+     * consecutive calls to \ref resolvePool performed in this
+     * mode too. Call \ref setUpgradeMode to turn this mode off.
      *
-     * To be run with great caution. It basically brings your
-     * system 'back to start'.
-     * Quite helpful to get back to a 'sane state'. Quite disastrous
-     * since you'll loose all non-distribution packages
+     * \see \ref addUpgradeRepo
      **/
-    void doUpgrade( UpgradeStatistics & opt_stats_r );
+    bool doUpgrade();
 
     /**
-     * Return the list of problematic update items
-     * i.e. locked ones (due to foreign vendor)
+     * Update to newest package
+     *
+     * Install the newest version of your installed packages as
+     * far as possible. This means a newer package will NOT be
+     * installed if it generates dependency problems.
+     * So the user will not get an error message.
+     *
+     **/
+    void doUpdate( );
+
+    /**
+     * Unmaintained packages which does not fit to
+     * the updated system (broken dependencies) will be
+     * deleted.
+     * Return the list of deleted items.
+     * Note : This list is valid after the call doUpgrade() only.
      **/
-    std::list<PoolItem_Ref> problematicUpdateItems( void ) const;
+    std::list<PoolItem> problematicUpdateItems() const;
 
     /**
      * Return the dependency problems found by the last call to
@@ -140,11 +160,6 @@ namespace zypp
      **/
     ResolverProblemList problems();
 
-    /**
-     * Return more solver information if an error has happened.
-     **/
-      
-    std::list<std::string> problemDescription( void ) const;      
 
     /**
      * Apply problem solutions. No more than one solution per problem
@@ -152,95 +167,264 @@ namespace zypp
      **/
     void applySolutions( const ProblemSolutionList & solutions );
 
-    Arch architecture() const;
-    void setArchitecture( const Arch & arch);
+    /**
+     * Return the \ref Transaction computed by the last solver run.
+     */
+    sat::Transaction getTransaction();
 
-    /**      
+    /**
      * Remove resolvables which are conflicts with others or
      * have unfulfilled requirements.
      * This behaviour is favourited by ZMD.
      **/
-    void setForceResolve (const bool force);
-    const bool forceResolve();
+    void setForceResolve( bool force );
+    bool forceResolve() const;
+
+    /**
+     * Ignore recommended packages that were already recommended by
+     * the installed packages
+     **/
+    void setIgnoreAlreadyRecommended( bool yesno_r );
+    bool ignoreAlreadyRecommended() const;
+
+    /**
+     * Setting whether required packages are installed ONLY
+     * So recommended packages, language packages and packages which depend
+     * on hardware (modalias) will not be regarded.
+     **/
+    void setOnlyRequires( bool yesno_r );
+    void resetOnlyRequires(); // set back to default (described in zypp.conf)
+    bool onlyRequires() const;
 
     /**
-     * transact a single ResObject
+     * Setting whether the solver should perform in 'upgrade' mode or
+     * not.
+     * \see \ref doUpgrade.
+     */
+    void setUpgradeMode( bool yesno_r );
+    bool upgradeMode() const;
+
+    /**
+     * Setting whether the solver should allow or disallow vendor changes.
      *
-     * Installs (install == true) or removes (install == false) all required
-     * and recommended packages(!) of \c robj
-     * (More or less a 'single step' resolver call)
+     * If OFF (the default) the solver will replace packages with packages
+     * of the same (or equivalent) vendor ony.
      *
-     * returns false if requirements are not all fulfillable
+     * \see \ref VendorAttr for definition of vendor equivalence.
+     **/
+    void setAllowVendorChange( bool yesno_r );
+    void setDefaultAllowVendorChange(); // set back to default (in zypp.conf)
+    bool allowVendorChange() const;
+
+    /**
+     * System verification mode also monitors and repairs dependencies
+     * of already installed packages.
+     * \see \ref verifySystem
+     */
+    void setSystemVerification( bool yesno_r );
+    void setDefaultSystemVerification();
+    bool systemVerification() const;
+
+    /**
+     * Set whether to solve source packages build dependencies per default.
+     * Usually turned off and if, enabled per source package.
+     * \NOTE This affects only source packges selected in the \ref ResPool. No solver rule
+     * will be generated for them. Source packages requested via e.g. \ref addRequire will
+     * always be solved.
+     * \NOTE Be carefull. The older the source package is, the stranger may be the
+     * result of solving it's build dependencies.
+     */
+    void setSolveSrcPackages( bool yesno_r );
+    void setDefaultSolveSrcPackages();
+    bool solveSrcPackages() const;
+
+    /**
+     * Cleanup when deleting packages. Whether the solver should per default
+     * try to remove packages exclusively required by the ones he's asked to delete.
+     */
+    void setCleandepsOnRemove( bool yesno_r );
+    void setDefaultCleandepsOnRemove(); // set back to default (in zypp.conf)
+    bool cleandepsOnRemove() const;
+
+    /** \name  Solver flags for DUP mode.
+     * DUP mode default settings differ from 'ordinary' ones. Default for
+     * all DUP flags is \c true.
+     */
+    //@{
+    /** dup mode: allow to downgrade installed solvable */
+    void dupSetAllowDowngrade( bool yesno_r );
+    void dupSetDefaultAllowDowngrade();                // Set back to default (in zypp.conf)
+    bool dupAllowDowngrade() const;
+
+    /** dup mode: allow to change name of installed solvable */
+    void dupSetAllowNameChange( bool yesno_r );
+    void dupSetDefaultAllowNameChange();       // Set back to default (in zypp.conf)
+    bool dupAllowNameChange() const;
+
+    /** dup mode: allow to change architecture of installed solvables */
+    void dupSetAllowArchChange( bool yesno_r );
+    void dupSetDefaultAllowArchChange();       // Set back to default (in zypp.conf)
+    bool dupAllowArchChange() const;
+
+    /**  dup mode: allow to change vendor of installed solvables*/
+    void dupSetAllowVendorChange( bool yesno_r );
+    void dupSetDefaultAllowVendorChange();     // Set back to default (in zypp.conf)
+    bool dupAllowVendorChange() const;
+    //@}
+
+    /** \name Upgrade to content of a specific repository.
+     * \note This is an ordinary solver request. You should simply
+     * \ref resolvePool to execute, and not \ref doUpgrade.
+     */
+    //@{
+    /**
+     * Adding request to perform a dist upgrade restricted to this repository.
      *
+     * This is what e.g. <tt>zypper dup --repo myrepo</tt> should perform.
+     * \see \ref doUpgrade
      */
-    bool transactResObject( ResObject::constPtr robj, bool install = true);
+    void addUpgradeRepo( Repository repo_r );
 
     /**
-     * transact all objects of this kind
+     * Whether there is at least one \c UpgradeRepo request pending
+     */
+    bool upgradingRepos() const;
+
+    /**
+     * Whether there is an \c UpgradeRepo request pending for this repo.
+     */
+    bool upgradingRepo( Repository repo_r ) const;
+
+    /**
+     * Remove an upgrade request for this repo.
+     */
+    void removeUpgradeRepo( Repository repo_r );
+
+    /**
+     * Remove all upgrade repo requests.
+     */
+    void removeUpgradeRepos();
+    //@}
+
+    /**
+     * Adding additional requirement
      *
-     * Look through the pool and runs transactResObject, first for removes
-     * then for installs
-     * (More or less a 'single step' resolver call)
+     */
+    void addRequire( const Capability & capability );
+
+    /**
+     * Adding additional conflict
      *
-     * returns false if any transactResObject() call returned false.
+     */
+    void addConflict( const Capability & capability );
+
+    /**
+     * Remove the additional requirement set by \ref addRequire(Capability).
      *
      */
-    bool transactResKind( Resolvable::Kind kind );
+    void removeRequire( const Capability & capability );
 
     /**
-     * reset any transact states
+     * Remove the additional conflict set by \ref addConflict(Capability).
      *
-     * Look through the pool and clear transact state.
-     * It will only reset states which have an equal or
-     * lower causer
+     */
+    void removeConflict( const Capability & capability );
+
+    /**
+     * Get all the additional requirements set by \ref addRequire(Capability).
      *
      */
-    void transactReset( ResStatus::TransactByValue causer );
+    CapabilitySet getRequire() const;
 
     /**
-     * Setting solver timeout
+     * Get all the additional conflicts set by \ref addConflict(Capability).
      *
-     * Stop solving after a given timeframe (seconds) 
-     * seconds = 0 : No timeout
+     */
+    CapabilitySet getConflict() const;
+
+    /**
+     * Generates a solver Testcase of the current state
      *
+     * \parame dumpPath destination directory of the created directory
+     * \return true if it was successful
      */
-    void setTimeout( int seconds );
+    bool createSolverTestcase( const std::string & dumpPath = "/var/log/YaST2/solverTestcase", bool runSolver = true );
 
     /**
-     * Getting solver timeout in seconds
+     * Gives information about WHO has pused an installation of an given item.
+     *
+     * \param item    Evaluate additional information for this resolvable.
+     * \return A list of structures which contains:
+     *         item                Item which has triggered the installation of the given param item.
+     *          initialInstallation This item has triggered the installation
+     *                             Not already fullfilled requierement only.
+     *         cap                 Capability which has triggerd this installation
+     *         capKind             Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
+     *
+     * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
      *
      */
-    int timeout();      
+    solver::detail::ItemCapKindList isInstalledBy( const PoolItem & item );
 
     /**
-     * Restricting solver passes
+     * Gives information about WHICH additional items will be installed due the installation of an item.
      *
-     * Stop solving after a given amount of passes
-     * count = 0 : No restriction
+     * \param item     Evaluate additional information for this resolvable.
+     * \return A list of structures which contains:
+     *         item                Item which has triggered the installation of the given param item.
+     *          initialInstallation This item has triggered the installation
+     *                             Not already fullfilled requierement only.
+     *         cap                 Capability which has triggerd this installation
+     *         capKind             Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
+     *
+     * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
      *
      */
-    void setMaxSolverPasses (int count);
+    solver::detail::ItemCapKindList installs( const PoolItem & item );
 
     /**
-     * Count of max solver passes
+     * Gives information about WHICH installed items are requested by the installation of an item.
+     *
+     * \param item     Evaluate additional information for this resolvable.
+     * \return A list of structures which contains:
+     *         item                Item which has triggered the installation of the given param item.
+     *          initialInstallation This item has triggered the installation
+     *                             Not already fullfilled requierement only.
+     *         cap                 Capability which has triggerd this installation
+     *         capKind             Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
+     *
+     * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
      *
      */
-    int maxSolverPasses ();
+    solver::detail::ItemCapKindList satifiedByInstalled( const PoolItem & item );
+
 
     /**
-     * Generates a solver Testcase of the current state
+     * Gives information about WHICH items require an already installed item.
+     *
+     * \param item     Evaluate additional information for this resolvable.
+     * \return A list of structures which contains:
+     *         item                Item which has triggered the installation of the given param item.
+     *          initialInstallation This item has triggered the installation
+     *                             Not already fullfilled requierement only.
+     *         cap                 Capability which has triggerd this installation
+     *         capKind             Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
+     *
+     * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
      *
-     * return true if it was successful     
      */
-    bool createSolverTestcase (const std::string & dumpPath = "/var/log/YaST2/solverTestcase");      
+    solver::detail::ItemCapKindList installedSatisfied( const PoolItem & item );
 
-  protected:
 
   private:
-    solver::detail::Resolver_Ptr _pimpl;
+    friend std::ostream & operator<<( std::ostream & str, const Resolver & obj );
+    zypp::RW_pointer<solver::detail::ResolverInternal> _pimpl;
   };
   ///////////////////////////////////////////////////////////////////
 
+  /** \relates Resolver Stream output */
+  std::ostream & operator<<( std::ostream & str, const Resolver & obj );
+
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////