libzypp  17.25.1
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/solver/Types.h>
34 #include <zypp/base/SerialNumber.h>
35 
37 namespace zypp
38 {
39  namespace sat
40  {
41  class Transaction;
42  }
44  namespace solver
45  {
47  namespace detail
48  {
49  class SATResolver;
50  typedef std::list<PoolItem> PoolItemList;
51  typedef std::set<PoolItem> PoolItemSet;
52 
54 //
55 // CLASS NAME : Resolver
63 class Resolver : private base::NonCopyable
64 {
65  typedef std::multimap<PoolItem,ItemCapKind> ItemCapKindMap;
66  private:
67  ResPool _pool;
68  SATResolver *_satResolver;
69  SerialNumberWatcher _poolchanged;
70 
71  CapabilitySet _extra_requires;
72  CapabilitySet _extra_conflicts;
73  std::set<Repository> _upgradeRepos;
74 
75  // Regard dependencies of the item weak onl
76  PoolItemList _addWeak;
77 
80  bool _upgradeMode; // Resolver has been called with doUpgrade
81  bool _updateMode; // Resolver has been called with doUpdate
82  bool _verifying; // The system will be checked
83  bool _onlyRequires; // do install required resolvables only
84  // no recommended resolvables, language
85  // packages, hardware packages (modalias)
86  bool _solveSrcPackages; // whether to generate solver jobs for selected source packges.
87  bool _cleandepsOnRemove; // whether removing a package should also remove no longer needed requirements
88 
89  bool _ignoreAlreadyRecommended; //ignore recommended packages that have already been recommended by the installed packages
91 
92  // Additional QueueItems which has to be regarded by the solver
93  // This will be used e.g. by solution actions
94  solver::detail::SolverQueueItemList _removed_queue_items;
95  solver::detail::SolverQueueItemList _added_queue_items;
96 
97  // Additional information about the solverrun
98  ItemCapKindMap _isInstalledBy;
99  ItemCapKindMap _installs;
100  ItemCapKindMap _satifiedByInstalled;
101  ItemCapKindMap _installedSatisfied;
102 
103  // helpers
104  void collectResolverInfo();
105 
106  // Unmaintained packages which does not fit to the updated system
107  // (broken dependencies) will be deleted.
108  // returns true if solving was successful
109  bool checkUnmaintainedItems ();
110 
111  void solverInit();
112 
113  public:
114 
115  Resolver( const ResPool & pool );
116  virtual ~Resolver();
117 
118  // ---------------------------------- I/O
119 
120  std::ostream & dumpOn( std::ostream & str ) const;
121 
122  friend std::ostream& operator<<( std::ostream& str, const Resolver & obj )
123  { return obj.dumpOn (str); }
124 
125  // ---------------------------------- methods
126 
127  ResPool pool() const;
128  void setPool( const ResPool & pool ) { _pool = pool; }
129 
130  void addUpgradeRepo( Repository repo_r ) { if ( repo_r && ! repo_r.isSystemRepo() ) _upgradeRepos.insert( repo_r ); }
131  bool upgradingRepo( Repository repo_r ) const { return( _upgradeRepos.find( repo_r ) != _upgradeRepos.end() ); }
132  void removeUpgradeRepo( Repository repo_r ) { _upgradeRepos.erase( repo_r ); }
133  void removeUpgradeRepos() { _upgradeRepos.clear(); }
134  const std::set<Repository> & upgradeRepos() const { return _upgradeRepos; }
135 
136  void addExtraRequire( const Capability & capability );
137  void removeExtraRequire( const Capability & capability );
138  void addExtraConflict( const Capability & capability );
139  void removeExtraConflict( const Capability & capability );
140 
141  void removeQueueItem( SolverQueueItem_Ptr item );
142  void addQueueItem( SolverQueueItem_Ptr item );
143 
144  CapabilitySet extraRequires() const { return _extra_requires; }
145  CapabilitySet extraConflicts() const { return _extra_conflicts; }
146 
147  void addWeak( const PoolItem & item );
148 
149  bool verifySystem();
150  bool resolvePool();
151  bool resolveQueue( SolverQueueItemList & queue );
152  void doUpdate();
153 
154  bool doUpgrade();
155  PoolItemList problematicUpdateItems() const;
156 
159  bool ignoreAlreadyRecommended() const { return _ignoreAlreadyRecommended; }
160  void setIgnoreAlreadyRecommended( bool yesno_r ) { _ignoreAlreadyRecommended = yesno_r; }
161 
162  bool onlyRequires () const { return _onlyRequires; }
163  void setOnlyRequires( TriBool state_r );
164 
165  bool isUpgradeMode() const { return _upgradeMode; }// Resolver has been called with doUpgrade
166  void setUpgradeMode( bool yesno_r ) { _upgradeMode = yesno_r; }
167 
168  bool isUpdateMode() const { return _updateMode; } // Resolver has been called with doUpdate
169  void setUpdateMode( bool yesno_r ) { _updateMode = yesno_r; }
170 
171  bool isVerifyingMode() const { return _verifying; } // The system will be checked
172  void setVerifyingMode( TriBool state_r ) { _verifying = indeterminate(state_r) ? false : bool(state_r); }
173 
174  bool solveSrcPackages() const { return _solveSrcPackages; }
175  void setSolveSrcPackages( TriBool state_r ) { _solveSrcPackages = indeterminate(state_r) ? false : bool(state_r); }
176 
177  bool cleandepsOnRemove() const { return _cleandepsOnRemove; }
178  void setCleandepsOnRemove( TriBool state_r );
180 
181  void setFocus( ResolverFocus focus_r );
182  ResolverFocus focus() const;
183 
184 #define ZOLV_FLAG_TRIBOOL( ZSETTER, ZGETTER ) \
185  void ZSETTER( TriBool state_r ); \
186  bool ZGETTER() const; \
187 
188  ZOLV_FLAG_TRIBOOL( setForceResolve, forceResolve )
189 
190  ZOLV_FLAG_TRIBOOL( setAllowDowngrade, allowDowngrade )
191  ZOLV_FLAG_TRIBOOL( setAllowNameChange, allowNameChange )
192  ZOLV_FLAG_TRIBOOL( setAllowArchChange, allowArchChange )
193  ZOLV_FLAG_TRIBOOL( setAllowVendorChange, allowVendorChange )
194 
195  ZOLV_FLAG_TRIBOOL( dupSetAllowDowngrade, dupAllowDowngrade )
196  ZOLV_FLAG_TRIBOOL( dupSetAllowNameChange, dupAllowNameChange )
197  ZOLV_FLAG_TRIBOOL( dupSetAllowArchChange, dupAllowArchChange )
198  ZOLV_FLAG_TRIBOOL( dupSetAllowVendorChange, dupAllowVendorChange )
199 
200 #undef ZOLV_FLAG_TRIBOOL
201 
202  ResolverProblemList problems() const;
203 
204  void applySolutions( const ProblemSolutionList & solutions );
205  bool applySolution( const ProblemSolution & solution );
206 
207  // Return the Transaction computed by the last solver run.
208  sat::Transaction getTransaction();
209 
210  // reset all SOLVER transaction in pool
211  void undo();
212 
213  void reset( bool keepExtras = false );
214 
215  // Get more information about the solverrun
216  // Which item will be installed by another item or triggers an item for
217  // installation
218  ItemCapKindList isInstalledBy( const PoolItem & item );
219  ItemCapKindList installs( const PoolItem & item );
220  ItemCapKindList satifiedByInstalled (const PoolItem & item );
221  ItemCapKindList installedSatisfied( const PoolItem & item );
222 
223 public:
225  sat::detail::CSolver * get() const;
226 };
227 
229  };// namespace detail
232  };// namespace solver
235 };// namespace zypp
237 #endif // ZYPP_USE_RESOLVER_INTERNALS
238 #endif // ZYPP_SOLVER_DETAIL_RESOLVER_H
zypp::solver::detail::dupAllowDowngrade
dupAllowDowngrade
Definition: Resolver.cc:123
Types.h
zypp::solver::detail::allowVendorChange
allowVendorChange
Definition: Resolver.cc:121
zypp::ProblemSolutionList
std::list< ProblemSolution_Ptr > ProblemSolutionList
Definition: ProblemTypes.h:43
zypp::ResolverFocus
ResolverFocus
The resolvers general attitude.
Definition: ResolverFocus.h:21
zypp::sat::detail::CSolver
::s_Solver CSolver
Wrapped libsolv C data type exposed as backdoor.
Definition: PoolMember.h:65
bool
zypp::CapabilitySet
std::unordered_set< Capability > CapabilitySet
Definition: Capability.h:33
zypp::solver::detail::ZOLV_FLAG_TRIBOOL
ZOLV_FLAG_TRIBOOL(setAllowNameChange, allowNameChange, _allownamechange, true) ZOLV_FLAG_TRIBOOL(setAllowVendorChange
zypp::solver::detail::SolverQueueItemList
std::list< SolverQueueItem_Ptr > SolverQueueItemList
Definition: Types.h:45
zypp::base::NonCopyable
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::solver::detail::operator<<
std::ostream & operator<<(std::ostream &os, const SolutionActionList &actionlist)
Definition: SolutionAction.cc:81
zypp::solver::detail::dupAllowArchChange
dupAllowArchChange
Definition: Resolver.cc:125
SerialNumber.h
zypp::ResolverProblemList
std::list< ResolverProblem_Ptr > ResolverProblemList
Definition: ProblemTypes.h:46
str
String related utilities and Regular expression matching.
zypp::TriBool
boost::logic::tribool TriBool
3-state boolean logic (true, false and indeterminate).
Definition: String.h:30
zypp::solver::detail::ItemCapKindList
std::list< ItemCapKind > ItemCapKindList
Definition: Types.h:41
zypp::solver::detail::dupAllowNameChange
dupAllowNameChange
Definition: Resolver.cc:124
zypp::solver::detail::dupAllowVendorChange
dupAllowVendorChange
Definition: Resolver.cc:126
zypp::dumpOn
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
Definition: Capability.cc:443