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