libzypp  15.28.6
Resolver.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* Resolver.h
3  *
4  * Copyright (C) 2000-2002 Ximian, Inc.
5  * Copyright (C) 2005 SUSE Linux Products GmbH
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License,
9  * version 2, as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19  * 02111-1307, USA.
20  */
21 
22 #ifndef ZYPP_SOLVER_DETAIL_RESOLVER_H
23 #define ZYPP_SOLVER_DETAIL_RESOLVER_H
24 #ifndef ZYPP_USE_RESOLVER_INTERNALS
25 #error Do not directly include this file!
26 #else
27 
28 #include <iosfwd>
29 #include <string>
30 #include <list>
31 #include <map>
32 
33 #include "zypp/ResPool.h"
34 #include "zypp/TriBool.h"
35 #include "zypp/base/SerialNumber.h"
36 #include "zypp/base/NonCopyable.h"
37 
38 #include "zypp/ProblemTypes.h"
39 #include "zypp/ResolverProblem.h"
40 #include "zypp/ProblemSolution.h"
41 #include "zypp/Capabilities.h"
42 #include "zypp/Capability.h"
43 
45 namespace zypp
46 {
47  namespace sat
48  {
49  class Transaction;
50  }
52  namespace solver
53  {
55  namespace detail
56  {
57  class SATResolver;
58  typedef std::list<PoolItem> PoolItemList;
59  typedef std::set<PoolItem> PoolItemSet;
60 
62 //
63 // CLASS NAME : Resolver
71 class Resolver : private base::NonCopyable
72 {
73  typedef std::multimap<PoolItem,ItemCapKind> ItemCapKindMap;
74  private:
75  ResPool _pool;
76  SATResolver *_satResolver;
77  SerialNumberWatcher _poolchanged;
78 
79  CapabilitySet _extra_requires;
80  CapabilitySet _extra_conflicts;
81  std::set<Repository> _upgradeRepos;
82 
83  // Regard dependencies of the item weak onl
84  PoolItemList _addWeak;
85 
88  bool _forceResolve; // remove items which are conflicts with others or
89  // have unfulfilled requirements.
90  // This behaviour is favourited by ZMD
91  bool _upgradeMode; // Resolver has been called with doUpgrade
92  bool _updateMode; // Resolver has been called with doUpdate
93  bool _verifying; // The system will be checked
94  bool _onlyRequires; // do install required resolvables only
95  // no recommended resolvables, language
96  // packages, hardware packages (modalias)
97  bool _solveSrcPackages; // whether to generate solver jobs for selected source packges.
98  bool _cleandepsOnRemove; // whether removing a package should also remove no longer needed requirements
99 
100  bool _ignoreAlreadyRecommended; //ignore recommended packages that have already been recommended by the installed packages
102 
103  // Additional QueueItems which has to be regarded by the solver
104  // This will be used e.g. by solution actions
105  solver::detail::SolverQueueItemList _removed_queue_items;
106  solver::detail::SolverQueueItemList _added_queue_items;
107 
108  // Additional information about the solverrun
109  ItemCapKindMap _isInstalledBy;
110  ItemCapKindMap _installs;
111  ItemCapKindMap _satifiedByInstalled;
112  ItemCapKindMap _installedSatisfied;
113 
114  // helpers
115  void collectResolverInfo();
116 
117  // Unmaintained packages which does not fit to the updated system
118  // (broken dependencies) will be deleted.
119  // returns true if solving was successful
120  bool checkUnmaintainedItems ();
121 
122  void solverInit();
123 
124  public:
125 
126  Resolver( const ResPool & pool );
127  virtual ~Resolver();
128 
129  // ---------------------------------- I/O
130 
131  std::ostream & dumpOn( std::ostream & str ) const;
132 
133  friend std::ostream& operator<<( std::ostream& str, const Resolver & obj )
134  { return obj.dumpOn (str); }
135 
136  // ---------------------------------- methods
137 
138  ResPool pool() const;
139  void setPool( const ResPool & pool ) { _pool = pool; }
140 
141  void addUpgradeRepo( Repository repo_r ) { if ( repo_r && ! repo_r.isSystemRepo() ) _upgradeRepos.insert( repo_r ); }
142  bool upgradingRepo( Repository repo_r ) const { return( _upgradeRepos.find( repo_r ) != _upgradeRepos.end() ); }
143  void removeUpgradeRepo( Repository repo_r ) { _upgradeRepos.erase( repo_r ); }
144  void removeUpgradeRepos() { _upgradeRepos.clear(); }
145  const std::set<Repository> & upgradeRepos() const { return _upgradeRepos; }
146 
147  void addExtraRequire( const Capability & capability );
148  void removeExtraRequire( const Capability & capability );
149  void addExtraConflict( const Capability & capability );
150  void removeExtraConflict( const Capability & capability );
151 
152  void removeQueueItem( SolverQueueItem_Ptr item );
153  void addQueueItem( SolverQueueItem_Ptr item );
154 
155  CapabilitySet extraRequires() const { return _extra_requires; }
156  CapabilitySet extraConflicts() const { return _extra_conflicts; }
157 
158  void addWeak( const PoolItem & item );
159 
160  bool verifySystem();
161  bool resolvePool();
162  bool resolveQueue( SolverQueueItemList & queue );
163  void doUpdate();
164 
165  bool doUpgrade();
166  PoolItemList problematicUpdateItems() const;
167 
170  bool ignoreAlreadyRecommended() const { return _ignoreAlreadyRecommended; }
171  void setIgnoreAlreadyRecommended( bool yesno_r ) { _ignoreAlreadyRecommended = yesno_r; }
172 
173  bool onlyRequires () const { return _onlyRequires; }
174  void setOnlyRequires( TriBool state_r );
175 
176  bool forceResolve() const { return _forceResolve; }
177  void setForceResolve( TriBool state_r ) { _forceResolve = indeterminate(state_r) ? false : bool(state_r); }
178 
179  bool isUpgradeMode() const { return _upgradeMode; }// Resolver has been called with doUpgrade
180  void setUpgradeMode( bool yesno_r ) { _upgradeMode = yesno_r; }
181 
182  bool isUpdateMode() const { return _updateMode; } // Resolver has been called with doUpdate
183 
184  bool isVerifyingMode() const { return _verifying; } // The system will be checked
185  void setVerifyingMode( TriBool state_r ) { _verifying = indeterminate(state_r) ? false : bool(state_r); }
186 
187  bool solveSrcPackages() const { return _solveSrcPackages; }
188  void setSolveSrcPackages( TriBool state_r ) { _solveSrcPackages = indeterminate(state_r) ? false : bool(state_r); }
189 
190  bool cleandepsOnRemove() const { return _cleandepsOnRemove; }
191  void setCleandepsOnRemove( TriBool state_r );
193 
194 #define ZOLV_FLAG_TRIBOOL( ZSETTER, ZGETTER ) \
195  void ZSETTER( TriBool state_r ); \
196  bool ZGETTER() const; \
197 
198  ZOLV_FLAG_TRIBOOL( setAllowDowngrade, allowDowngrade )
199  ZOLV_FLAG_TRIBOOL( setAllowNameChange, allowNameChange )
200  ZOLV_FLAG_TRIBOOL( setAllowArchChange, allowArchChange )
201  ZOLV_FLAG_TRIBOOL( setAllowVendorChange, allowVendorChange )
202 
203  ZOLV_FLAG_TRIBOOL( dupSetAllowDowngrade, dupAllowDowngrade )
204  ZOLV_FLAG_TRIBOOL( dupSetAllowNameChange, dupAllowNameChange )
205  ZOLV_FLAG_TRIBOOL( dupSetAllowArchChange, dupAllowArchChange )
206  ZOLV_FLAG_TRIBOOL( dupSetAllowVendorChange, dupAllowVendorChange )
207 
208 #undef ZOLV_FLAG_TRIBOOL
209 
210  ResolverProblemList problems() const;
211 
212  void applySolutions( const ProblemSolutionList & solutions );
213  bool applySolution( const ProblemSolution & solution );
214 
215  // Return the Transaction computed by the last solver run.
216  sat::Transaction getTransaction();
217 
218  // reset all SOLVER transaction in pool
219  void undo();
220 
221  void reset( bool keepExtras = false );
222 
223  // Get more information about the solverrun
224  // Which item will be installed by another item or triggers an item for
225  // installation
226  ItemCapKindList isInstalledBy( const PoolItem & item );
227  ItemCapKindList installs( const PoolItem & item );
228  ItemCapKindList satifiedByInstalled (const PoolItem & item );
229  ItemCapKindList installedSatisfied( const PoolItem & item );
230 
231 };
232 
234  };// namespace detail
237  };// namespace solver
240 };// namespace zypp
242 #endif // ZYPP_USE_RESOLVER_INTERNALS
243 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H
std::list< ProblemSolution_Ptr > ProblemSolutionList
Definition: ProblemTypes.h:43
std::list< SolverQueueItem_Ptr > SolverQueueItemList
Definition: Types.h:45
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: String.h:30
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
std::list< ResolverProblem_Ptr > ResolverProblemList
Definition: ProblemTypes.h:46
ostream & operator<<(ostream &os, const SolutionActionList &actionlist)
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:446
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
std::list< ItemCapKind > ItemCapKindList
Definition: Types.h:41
ZOLV_FLAG_TRIBOOL(setAllowNameChange, allowNameChange, _allownamechange, true) ZOLV_FLAG_TRIBOOL(setAllowVendorChange