1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
4 * Easy-to use interface to the ZYPP dependency resolver
6 * Copyright (C) 2000-2002 Ximian, Inc.
7 * Copyright (C) 2005 SUSE Linux Products GmbH
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License,
11 * version 2, as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 #include "zypp/solver/detail/Resolver.h"
25 #include "zypp/solver/detail/SolutionAction.h"
26 #include "zypp/CapSet.h"
27 #include "zypp/base/Logger.h"
28 #include "zypp/Dependencies.h"
31 /////////////////////////////////////////////////////////////////////////
33 { ///////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////
36 { /////////////////////////////////////////////////////////////////////
37 /////////////////////////////////////////////////////////////////////
39 { ///////////////////////////////////////////////////////////////////
43 IMPL_PTR_TYPE(SolutionAction);
44 IMPL_PTR_TYPE(TransactionSolutionAction);
45 IMPL_PTR_TYPE(InjectSolutionAction);
47 //---------------------------------------------------------------------------
49 SolutionAction::SolutionAction()
54 SolutionAction::~SolutionAction()
59 //---------------------------------------------------------------------------
62 TransactionSolutionAction::dumpOn( ostream& os) const
64 os << "TransactionSolutionAction: ";
66 case KEEP: os << "Keep"; break;
67 case INSTALL: os << "Install"; break;
68 case REMOVE: os << "Remove"; break;
69 case UNLOCK: os << "Unlock"; break;
70 case ALLBRANCHES_ON: os << "All branches on"; break;
71 case ALLBRANCHES_OFF: os << "All branches off"; break;
72 case DOUBLETIMEOUT: os << "Double timeout"; break;
82 operator<<( ostream& os, const SolutionActionList & actionlist)
84 for (SolutionActionList::const_iterator iter = actionlist.begin(); iter != actionlist.end(); ++iter) {
93 operator<<( ostream& os, const CSolutionActionList & actionlist)
95 for (CSolutionActionList::const_iterator iter = actionlist.begin(); iter != actionlist.end(); ++iter) {
102 //---------------------------------------------------------------------------
105 InjectSolutionAction::dumpOn( ostream& os ) const
107 os << "InjectSolutionAction: ";
111 case REQUIRES: os << "Requires"; break;
112 case CONFLICTS: os << "Conflicts"; break;
113 case OBSOLETES: os << "Obsoletes"; break;
114 case INSTALLED: os << "Installed"; break;
115 case ARCHITECTURE: os << "Architecture"; break;
116 case VENDOR: os << "Vendor"; break;
117 default: os << "Wrong kind"; break;
125 //---------------------------------------------------------------------------
129 SolutionAction::dumpOn( std::ostream & os ) const
131 os << "SolutionAction<";
132 os << "not specified";
139 TransactionSolutionAction::execute(Resolver & resolver) const
144 resolver.addIgnoreInstalledItem( _item );
147 if (_item.status().isToBeUninstalled())
148 ret = _item.status().setTransact (false, ResStatus::USER);
150 _item.status().setToBeInstalled (ResStatus::USER);
153 if (_item.status().isToBeInstalled()) {
154 _item.status().setTransact (false,ResStatus::USER);
155 _item.status().setLock (true,ResStatus::USER); // no other dependency can set it again
156 } else if (_item.status().isInstalled())
157 _item.status().setToBeUninstalled (ResStatus::USER);
159 _item.status().setLock (true,ResStatus::USER); // no other dependency can set it again
162 ret = _item.status().setLock (false, ResStatus::USER);
163 if (!ret) ERR << "Cannot unlock " << _item << endl;
166 resolver.setTryAllPossibilities (true);
168 case ALLBRANCHES_OFF:
169 resolver.setTryAllPossibilities (false);
172 resolver.setTimeout (resolver.timeout()*2);
175 ERR << "Wrong TransactionKind" << endl;
182 InjectSolutionAction::execute(Resolver & resolver) const
184 Dependencies dependencies;
186 if (_item != PoolItem_Ref()) {
187 dependencies = _item.resolvable()->deps();
188 depList = dependencies[Dep::CONFLICTS];
192 // removing conflict in both resolvables
193 for (CapSet::const_iterator iter = depList.begin(); iter != depList.end(); iter++) {
194 if (iter->matches (_capability) == CapMatch::yes )
196 resolver.addIgnoreConflict (_item, _capability);
199 // Obsoletes are conflicts too
200 depList = dependencies[Dep::OBSOLETES];
201 for (CapSet::const_iterator iter = depList.begin(); iter != depList.end(); iter++) {
202 if (iter->matches (_capability) == CapMatch::yes )
204 resolver.addIgnoreConflict (_otherItem, _capability);
208 dependencies = _otherItem.resolvable()->deps();
209 depList = dependencies[Dep::CONFLICTS];
210 for (CapSet::const_iterator iter = depList.begin(); iter != depList.end(); iter++) {
211 if (iter->matches (_capability) == CapMatch::yes )
213 resolver.addIgnoreConflict (_otherItem, _capability);
216 // Obsoletes are conflicts too
217 depList = dependencies[Dep::OBSOLETES];
218 for (CapSet::const_iterator iter = depList.begin(); iter != depList.end(); iter++) {
219 if (iter->matches (_capability) == CapMatch::yes )
221 resolver.addIgnoreConflict (_otherItem, _capability);
227 // removing the requires dependency from the item
228 if (_item == PoolItem_Ref()) {
229 // this was a requirement via Resolver::addExtraCapability
230 // so we have to delete it.
231 resolver.removeExtraCapability (_capability);
233 resolver.addIgnoreRequires (_item, _capability);
237 // This item is for ALL architectures available
238 resolver.addIgnoreArchitectureItem (_item);
241 // This item is for ALL vendor available
242 resolver.addIgnoreVendorItem (_item);
245 // removing the obsoletes dependency from the item
246 resolver.addIgnoreObsoletes (_otherItem, _capability);
249 // ignoring already installed items
250 resolver.addIgnoreInstalledItem (_item);
251 resolver.addIgnoreInstalledItem (_otherItem);
254 ERR << "No valid InjectSolutionAction kind found" << endl;
261 ///////////////////////////////////////////////////////////////////
262 };// namespace detail
263 /////////////////////////////////////////////////////////////////////
264 /////////////////////////////////////////////////////////////////////
265 };// namespace solver
266 ///////////////////////////////////////////////////////////////////////
267 ///////////////////////////////////////////////////////////////////////
269 /////////////////////////////////////////////////////////////////////////