libzypp 17.31.31
SolutionAction.cc
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2/* SolutionAction.cc
3 *
4 * Easy-to use interface to the ZYPP dependency resolver
5 *
6 * Copyright (C) 2000-2002 Ximian, Inc.
7 * Copyright (C) 2005 SUSE Linux Products GmbH
8 *
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.
12 *
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.
17 *
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
21 * 02111-1307, USA.
22 */
23
24#define ZYPP_USE_RESOLVER_INTERNALS
25
26#include <zypp/solver/detail/Resolver.h>
29#include <zypp/Capabilities.h>
30#include <zypp/base/Logger.h>
31
32using std::endl;
33
35namespace zypp
36{
38 namespace solver
39 {
41 namespace detail
42 {
43
44
45IMPL_PTR_TYPE(SolutionAction);
46
47//---------------------------------------------------------------------------
48
49SolutionAction::SolutionAction()
50{
51}
52
53
54SolutionAction::~SolutionAction()
55{
56}
57
58bool SolutionAction::skipsPatchesOnly() const
59{ return false; }
60
61//---------------------------------------------------------------------------
62
63std::ostream &
64TransactionSolutionAction::dumpOn( std::ostream& os) const
65{
66 os << "TransactionSolutionAction: ";
67 switch (_action) {
68 case KEEP: os << "Keep " << _item; break;
69 case INSTALL: os << "Install " << _item; break;
70 case REMOVE: os << "Remove " << _item; break;
71 case UNLOCK: os << "Unlock " << _item; break;
72 case LOCK: os << "Lock " << _item; break;
73 case REMOVE_EXTRA_REQUIRE: os << "Remove require " << _capability; break;
74 case REMOVE_EXTRA_CONFLICT: os << "Remove conflict " << _capability; break;
75 case ADD_SOLVE_QUEUE_ITEM: os << "Add SolveQueueItem " << _solverQueueItem; break;
76 case REMOVE_SOLVE_QUEUE_ITEM: os << "Remove SolveQueueItem " << _solverQueueItem; break;
77 }
78 return os;
79}
80
81
82std::ostream&
83operator<<( std::ostream& os, const SolutionActionList & actionlist)
84{
85 for (SolutionActionList::const_iterator iter = actionlist.begin(); iter != actionlist.end(); ++iter) {
86 os << *(*iter);
87 os << endl;
88 }
89 return os;
90}
91
92//---------------------------------------------------------------------------
93
94std::ostream &
95InjectSolutionAction::dumpOn( std::ostream& os ) const
96{
97 os << "InjectSolutionAction: ";
98 switch (_kind) {
99 case WEAK: os << "Weak"; break;
100 default: os << "Wrong kind"; break;
101 }
102 os << " ";
103 os << _item;
104 return os;
105}
106
107//---------------------------------------------------------------------------
108
109
110std::ostream &
111SolutionAction::dumpOn( std::ostream & os ) const
112{
113 os << "SolutionAction<";
114 os << "not specified";
115 os << "> ";
116 return os;
117}
118
119
120bool
121TransactionSolutionAction::execute(ResolverInternal & resolver) const
122{
123 bool ret = true;
124 switch (action()) {
125 case KEEP:
126 _item.status().resetTransact (ResStatus::USER);
127 ret = _item.status().setTransact (false, ResStatus::APPL_HIGH); // APPL_HIGH: Locking should not be saved permanently
128 break;
129 case INSTALL:
130 if (_item.status().isToBeUninstalled())
131 ret = _item.status().setTransact (false, ResStatus::USER);
132 else
133 _item.status().setToBeInstalled (ResStatus::USER);
134 break;
135 case REMOVE:
136 if (_item.status().isToBeInstalled()) {
137 _item.status().setTransact (false,ResStatus::USER);
138 _item.status().setLock (true,ResStatus::USER); // no other dependency can set it again
139 } else if (_item.status().isInstalled())
140 _item.status().setToBeUninstalled (ResStatus::USER);
141 else
142 _item.status().setLock (true,ResStatus::USER); // no other dependency can set it again
143 break;
144 case UNLOCK:
145 ret = _item.status().setLock (false, ResStatus::USER);
146 if (!ret) ERR << "Cannot unlock " << _item << endl;
147 break;
148 case LOCK:
149 _item.status().resetTransact (ResStatus::USER);
150 ret = _item.status().setLock (true, ResStatus::APPL_HIGH); // APPL_HIGH: Locking should not be saved permanently
151 if (!ret) ERR << "Cannot lock " << _item << endl;
152 break;
153 case REMOVE_EXTRA_REQUIRE:
154 resolver.removeExtraRequire (_capability);
155 break;
156 case REMOVE_EXTRA_CONFLICT:
157 resolver.removeExtraConflict (_capability);
158 break;
159 case ADD_SOLVE_QUEUE_ITEM:
160 resolver.addQueueItem(_solverQueueItem);
161 break;
162 case REMOVE_SOLVE_QUEUE_ITEM:
163 resolver.removeQueueItem(_solverQueueItem);
164 break;
165 default:
166 ERR << "Wrong TransactionKind" << endl;
167 ret = false;
168 }
169 return ret;
170}
171
172bool TransactionSolutionAction::skipsPatchesOnly() const
173{ return _action == KEEP && _item.isKind<Patch>(); }
174
175bool
176InjectSolutionAction::execute(ResolverInternal & resolver) const
177{
178 switch (_kind) {
179 case WEAK:
180 // set item dependencies to weak
181 resolver.addWeak (_item);
182 break;
183 default:
184 ERR << "No valid InjectSolutionAction kind found" << endl;
185 return false;
186 }
187
188 return true;
189}
190
192 };// namespace detail
195 };// namespace solver
198};// namespace zypp
Resolver ResolverInternal
Preferred name in API.
Definition Types.h:39
std::list< SolutionAction_Ptr > SolutionActionList
Definition Types.h:48
std::ostream & operator<<(std::ostream &os, const SolutionActionList &actionlist)
Easy-to use interface to the ZYPP dependency resolver.
#define ERR
Definition Logger.h:98
#define IMPL_PTR_TYPE(NAME)