f2ef0926721536ca3799e382fda7c7c2b7a792e2
[platform/upstream/libzypp.git] / zypp / Resolver.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/Resolver.h
10  *
11 */
12 #ifndef ZYPP_RESOLVER_H
13 #define ZYPP_RESOLVER_H
14
15 #include <iosfwd>
16 #include <functional>
17
18 #include "zypp/base/ReferenceCounted.h"
19 #include "zypp/base/PtrTypes.h"
20
21 #include "zypp/ResPool.h"
22 #include "zypp/solver/detail/Resolver.h"
23 #include "zypp/solver/detail/SolverQueueItem.h"
24 #include "zypp/ProblemTypes.h"
25
26 ///////////////////////////////////////////////////////////////////
27 namespace zypp
28 { /////////////////////////////////////////////////////////////////
29
30   namespace sat
31   {
32     class Transaction;
33   }
34
35   ///////////////////////////////////////////////////////////////////
36   //
37   //    CLASS NAME : Resolver
38   //
39   /**
40    * Dependency resolver interface.
41    *
42    * To resolve dependencies after making changes to the \ref ResPool (using
43    * \ref addRequire(), \ref addConflict(), \ref applySolutions(), or by making
44    * the changes directly on the \ref PoolItem status objects,
45    * call the \ref resolvePool() method.
46    */
47   class Resolver : public base::ReferenceCounted, private base::NonCopyable
48   {
49   public:
50
51     /** Ctor */
52     Resolver( const ResPool & pool );
53     /** Dtor */
54     virtual ~Resolver();
55
56     /**
57      * Resolve package dependencies:
58      *
59      * Enter \ref systemVerification mode to monitor and repair dependencies
60      * of already installed packages, and solve immediately.
61      *
62      * Call \ref setSystemVerification to turn of this mode.
63      **/
64     bool verifySystem();
65
66
67     /**
68      * Resolve package dependencies:
69      *
70      * Try to execute all pending transactions (there may be more than
71      * one!).
72      * The solver collects all transactions (install/delete resolvables)
73      * from the pool, generates task, solving it and writes the
74      * results back to pool
75      *
76      * Returns "true" on success (i.e., if there were no problems that
77      * need user interaction) and "false" if there were problems.  In
78      * the latter case, use problems() and later applySolutions()
79      * below.
80      **/
81     bool resolvePool();
82
83
84     /**
85      * Resolve package dependencies:
86      *
87      * The solver works off the given queue and writes back the solution
88      * to pool.
89      *
90      * Returns "true" on success (i.e., if there were no problems that
91      * need user interaction) and "false" if there were problems.  In
92      * the latter case, use problems() and later applySolutions()
93      * below.
94      * The solution could be that the solver remove/add some entries
95      * in the task queue. So make a new call of resolveQueue after you
96      * have applied any solution AND check the parameter "queue" if
97      * there has been any changes by the solver and adapt these changes
98      * to e.g. the selectables.
99      *
100      **/
101     bool resolveQueue( solver::detail::SolverQueueItemList & queue );
102
103     /*
104      * Undo solver changes done in resolvePool()
105      * Throwing away all ignored dependencies.
106      */
107     void undo();
108
109     /*
110      * Resets solver information and verify option.
111      */
112     void reset();
113
114
115     /**
116      * Do an distribution upgrade (DUP)
117      *
118      * Perform a distribution upgrade. This performs an update of
119      * all packages with a special resolver algorithm which takes
120      * care of package splits, pattern  and  product  updates,
121      * etc.
122      * This call also turns the solver into \ref upgradeMode, so
123      * consecutive calls to \ref resolvePool performed in this
124      * mode too. Call \ref setUpgradeMode to turn this mode off.
125      *
126      * \see \ref addUpgradeRepo
127      **/
128     bool doUpgrade();
129
130     /**
131      * Update to newest package
132      *
133      * Install the newest version of your installed packages as
134      * far as possible. This means a newer package will NOT be
135      * installed if it generates dependency problems.
136      * So the user will not get an error message.
137      *
138      **/
139     void doUpdate( );
140
141     /**
142      * Unmaintained packages which does not fit to
143      * the updated system (broken dependencies) will be
144      * deleted.
145      * Return the list of deleted items.
146      * Note : This list is valid after the call doUpgrade() only.
147      **/
148     std::list<PoolItem> problematicUpdateItems() const;
149
150     /**
151      * Return the dependency problems found by the last call to
152      * resolveDependencies(). If there were no problems, the returned
153      * list will be empty.
154      **/
155     ResolverProblemList problems();
156
157
158     /**
159      * Apply problem solutions. No more than one solution per problem
160      * can be applied.
161      **/
162     void applySolutions( const ProblemSolutionList & solutions );
163
164     /**
165      * Return the \ref Transaction computed by the last solver run.
166      */
167     sat::Transaction getTransaction();
168
169     /**
170      * Remove resolvables which are conflicts with others or
171      * have unfulfilled requirements.
172      * This behaviour is favourited by ZMD.
173      **/
174     void setForceResolve( bool force );
175     bool forceResolve() const;
176
177     /**
178      * Ignore recommended packages that were already recommended by
179      * the installed packages
180      **/
181     void setIgnoreAlreadyRecommended( bool yesno_r );
182     bool ignoreAlreadyRecommended() const;
183
184     /**
185      * Setting whether required packages are installed ONLY
186      * So recommended packages, language packages and packages which depend
187      * on hardware (modalias) will not be regarded.
188      **/
189     void setOnlyRequires( bool yesno_r );
190     void resetOnlyRequires(); // set back to default (described in zypp.conf)
191     bool onlyRequires() const;
192
193     /**
194      * Setting whether the solver should perform in 'upgrade' mode or
195      * not.
196      * \see \ref doUpgrade.
197      */
198     void setUpgradeMode( bool yesno_r );
199     bool upgradeMode() const;
200
201     /**
202      * Setting whether the solver should allow or disallow vendor changes.
203      *
204      * If OFF (the default) the solver will replace packages with packages
205      * of the same (or equivalent) vendor ony.
206      *
207      * \see \ref VendorAttr for definition of vendor equivalence.
208      **/
209     void setAllowVendorChange( bool yesno_r );
210     void setDefaultAllowVendorChange(); // set back to default (in zypp.conf)
211     bool allowVendorChange() const;
212
213     /**
214      * System verification mode also monitors and repairs dependencies
215      * of already installed packages.
216      * \see \ref verifySystem
217      */
218     void setSystemVerification( bool yesno_r );
219     void setDefaultSystemVerification();
220     bool systemVerification() const;
221
222     /**
223      * Set whether to solve source packages build dependencies per default.
224      * Usually turned off and if, enabled per source package.
225      * \NOTE This affects only source packges selected in the \ref ResPool. No solver rule
226      * will be generated for them. Source packages requested via e.g. \ref addRequire will
227      * always be solved.
228      * \NOTE Be carefull. The older the source package is, the stranger may be the
229      * result of solving it's build dependencies.
230      */
231     void setSolveSrcPackages( bool yesno_r );
232     void setDefaultSolveSrcPackages();
233     bool solveSrcPackages() const;
234
235     /**
236      * Cleanup when deleting packages. Whether the solver should per default
237      * try to remove packages exclusively required by the ones he's asked to delete.
238      */
239     void setCleandepsOnRemove( bool yesno_r );
240     void setDefaultCleandepsOnRemove(); // set back to default (in zypp.conf)
241     bool cleandepsOnRemove() const;
242
243     /** \name  Solver flags for DUP mode.
244      * DUP mode default settings differ from 'ordinary' ones. Default for
245      * all DUP flags is \c true.
246      */
247     //@{
248     /** dup mode: allow to downgrade installed solvable */
249     void dupSetAllowDowngrade( bool yesno_r );
250     void dupSetDefaultAllowDowngrade(); // Set back to default
251     bool dupAllowDowngrade() const;
252
253     /** dup mode: allow to change name of installed solvable */
254     void dupSetAllowNameChange( bool yesno_r );
255     void dupSetDefaultAllowNameChange();        // Set back to default
256     bool dupAllowNameChange() const;
257
258     /** dup mode: allow to change architecture of installed solvables */
259     void dupSetAllowArchChange( bool yesno_r );
260     void dupSetDefaultAllowArchChange();        // Set back to default
261     bool dupAllowArchChange() const;
262
263     /**  dup mode: allow to change vendor of installed solvables*/
264     void dupSetAllowVendorChange( bool yesno_r );
265     void dupSetDefaultAllowVendorChange();      // Set back to default
266     bool dupAllowVendorChange() const;
267     //@}
268
269     /** \name Upgrade to content of a specific repository.
270      * \note This is an ordinary solver request. You should simply
271      * \ref resolvePool to execute, and not \ref doUpgrade.
272      */
273     //@{
274     /**
275      * Adding request to perform a dist upgrade restricted to this repository.
276      *
277      * This is what e.g. <tt>zypper dup --repo myrepo</tt> should perform.
278      * \see \ref doUpgrade
279      */
280     void addUpgradeRepo( Repository repo_r );
281
282     /**
283      * Whether there is at least one \c UpgradeRepo request pending
284      */
285     bool upgradingRepos() const;
286
287     /**
288      * Whether there is an \c UpgradeRepo request pending for this repo.
289      */
290     bool upgradingRepo( Repository repo_r ) const;
291
292     /**
293      * Remove an upgrade request for this repo.
294      */
295     void removeUpgradeRepo( Repository repo_r );
296
297     /**
298      * Remove all upgrade repo requests.
299      */
300     void removeUpgradeRepos();
301     //@}
302
303     /**
304      * Adding additional requirement
305      *
306      */
307     void addRequire( const Capability & capability );
308
309     /**
310      * Adding additional conflict
311      *
312      */
313     void addConflict( const Capability & capability );
314
315     /**
316      * Remove the additional requirement set by \ref addRequire(Capability).
317      *
318      */
319     void removeRequire( const Capability & capability );
320
321     /**
322      * Remove the additional conflict set by \ref addConflict(Capability).
323      *
324      */
325     void removeConflict( const Capability & capability );
326
327     /**
328      * Get all the additional requirements set by \ref addRequire(Capability).
329      *
330      */
331     CapabilitySet getRequire() const;
332
333     /**
334      * Get all the additional conflicts set by \ref addConflict(Capability).
335      *
336      */
337     CapabilitySet getConflict() const;
338
339     /**
340      * Generates a solver Testcase of the current state
341      *
342      * \parame dumpPath destination directory of the created directory
343      * \return true if it was successful
344      */
345     bool createSolverTestcase( const std::string & dumpPath = "/var/log/YaST2/solverTestcase", bool runSolver = true );
346
347     /**
348      * Gives information about WHO has pused an installation of an given item.
349      *
350      * \param item    Evaluate additional information for this resolvable.
351      * \return A list of structures which contains:
352      *          item                Item which has triggered the installation of the given param item.
353      *          initialInstallation This item has triggered the installation
354      *                              Not already fullfilled requierement only.
355      *          cap                 Capability which has triggerd this installation
356      *          capKind             Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
357      *
358      * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
359      *
360      */
361     solver::detail::ItemCapKindList isInstalledBy( const PoolItem & item );
362
363     /**
364      * Gives information about WHICH additional items will be installed due the installation of an item.
365      *
366      * \param item     Evaluate additional information for this resolvable.
367      * \return A list of structures which contains:
368      *          item                Item which has triggered the installation of the given param item.
369      *          initialInstallation This item has triggered the installation
370      *                              Not already fullfilled requierement only.
371      *          cap                 Capability which has triggerd this installation
372      *          capKind             Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
373      *
374      * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
375      *
376      */
377     solver::detail::ItemCapKindList installs( const PoolItem & item );
378
379     /**
380      * Gives information about WHICH installed items are requested by the installation of an item.
381      *
382      * \param item     Evaluate additional information for this resolvable.
383      * \return A list of structures which contains:
384      *          item                Item which has triggered the installation of the given param item.
385      *          initialInstallation This item has triggered the installation
386      *                              Not already fullfilled requierement only.
387      *          cap                 Capability which has triggerd this installation
388      *          capKind             Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
389      *
390      * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
391      *
392      */
393     solver::detail::ItemCapKindList satifiedByInstalled( const PoolItem & item );
394
395
396     /**
397      * Gives information about WHICH items require an already installed item.
398      *
399      * \param item     Evaluate additional information for this resolvable.
400      * \return A list of structures which contains:
401      *          item                Item which has triggered the installation of the given param item.
402      *          initialInstallation This item has triggered the installation
403      *                              Not already fullfilled requierement only.
404      *          cap                 Capability which has triggerd this installation
405      *          capKind             Kind of that capability (e.g.  Dep::REQUIRES,Dep::RECOMMENDS,... )
406      *
407      * Note: In order to have a result start a solver run before. Not matter if it is valid or invalid.
408      *
409      */
410     solver::detail::ItemCapKindList installedSatisfied( const PoolItem & item );
411
412
413   private:
414     friend std::ostream & operator<<( std::ostream & str, const Resolver & obj );
415
416     typedef solver::detail::Resolver Impl;
417     zypp::RW_pointer<Impl,rw_pointer::Intrusive<Impl> > _pimpl;
418   };
419   ///////////////////////////////////////////////////////////////////
420
421   /** \relates Resolver Stream output */
422   std::ostream & operator<<( std::ostream & str, const Resolver & obj );
423
424   /////////////////////////////////////////////////////////////////
425 } // namespace zypp
426 ///////////////////////////////////////////////////////////////////
427 #endif // ZYPP_RESOLVER_H