libzypp 17.37.17
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
29#include <zypp/Capabilities.h>
30#include <zypp/base/Logger.h>
31
32using std::endl;
33
35namespace zypp::solver::detail {
36
38 // class SolutionAction
40
41 IMPL_PTR_TYPE(SolutionAction);
42
43 SolutionAction::SolutionAction()
44 {}
45
46 SolutionAction::~SolutionAction()
47 {}
48
49 std::ostream & SolutionAction::dumpOn( std::ostream & os ) const
50 { return os << "SolutionAction<not specified> "; }
51
52 PoolItem SolutionAction::item() const
53 { return PoolItem(); }
54
55 bool SolutionAction::skipsPatchesOnly() const
56 { return false; }
57
58 std::ostream & operator<<( std::ostream & str, const SolutionActionList & actionlist )
59 {
60 for ( const auto & itemptr : actionlist )
61 str << *itemptr << std::endl;
62 return str;
63 }
64
66 // class TransactionSolutionAction
68
69 std::ostream & TransactionSolutionAction::dumpOn( std::ostream & str ) const
70 {
71 str << "TransactionSolutionAction: ";
72 switch (_action) {
73 case KEEP: str << "Keep " << _item; break;
74 case INSTALL: str << "Install " << _item; break;
75 case REMOVE: str << "Remove " << _item; break;
76 case UNLOCK: str << "Unlock " << _item; break;
77 case LOCK: str << "Lock " << _item; break;
78 case REMOVE_EXTRA_REQUIRE: str << "Remove require " << _capability; break;
79 case REMOVE_EXTRA_CONFLICT: str << "Remove conflict " << _capability; break;
80 case ADD_SOLVE_QUEUE_ITEM: str << "Add SolveQueueItem " << _solverQueueItem; break;
81 case REMOVE_SOLVE_QUEUE_ITEM: str << "Remove SolveQueueItem " << _solverQueueItem; break;
82 }
83 return str;
84 }
85
86 bool TransactionSolutionAction::execute( ResolverInternal & resolver ) const
87 {
88 bool ret = true;
89 switch ( _action ) {
90 case KEEP:
91 _item.status().resetTransact( ResStatus::USER );
92 ret = _item.status().setTransact( false, ResStatus::APPL_HIGH ); // APPL_HIGH: Locking should not be saved permanently
93 break;
94 case INSTALL:
95 if ( _item.status().isToBeUninstalled() )
96 ret = _item.status().setTransact( false, ResStatus::USER );
97 else
98 _item.status().setToBeInstalled( ResStatus::USER );
99 break;
100 case REMOVE:
101 if ( _item.status().isToBeInstalled() ) {
102 _item.status().setTransact( false, ResStatus::USER );
103 _item.status().setLock( true, ResStatus::USER ); // no other dependency can set it again
104 } else if ( _item.status().isInstalled() )
105 _item.status().setToBeUninstalled( ResStatus::USER );
106 else
107 _item.status().setLock( true,ResStatus::USER ); // no other dependency can set it again
108 break;
109 case UNLOCK:
110 ret = _item.status().setLock( false, ResStatus::USER );
111 if ( !ret ) ERR << "Cannot unlock " << _item << endl;
112 break;
113 case LOCK:
114 _item.status().resetTransact( ResStatus::USER );
115 ret = _item.status().setLock( true, ResStatus::APPL_HIGH ); // APPL_HIGH: Locking should not be saved permanently
116 if ( !ret ) ERR << "Cannot lock " << _item << endl;
117 break;
118 case REMOVE_EXTRA_REQUIRE:
119 resolver.removeExtraRequire( _capability );
120 break;
121 case REMOVE_EXTRA_CONFLICT:
122 resolver.removeExtraConflict( _capability );
123 break;
124 case ADD_SOLVE_QUEUE_ITEM:
125 resolver.addQueueItem( _solverQueueItem );
126 break;
127 case REMOVE_SOLVE_QUEUE_ITEM:
128 resolver.removeQueueItem( _solverQueueItem );
129 break;
130 default:
131 ERR << "Wrong TransactionKind" << endl;
132 ret = false;
133 break;
134 }
135 return ret;
136 }
137
138 bool TransactionSolutionAction::skipsPatchesOnly() const
139 { return _action == KEEP && _item.isKind<Patch>(); }
140
142 // class InjectSolutionAction
144
145 std::ostream & InjectSolutionAction::dumpOn( std::ostream & str ) const
146 {
147 str << "InjectSolutionAction: ";
148 switch (_kind) {
149 case WEAK: str << "Weak"; break;
150 default: str << "Wrong kind"; break;
151 }
152 return str << " " << _item;
153 }
154
155 bool InjectSolutionAction::execute( ResolverInternal & resolver ) const
156 {
157 bool ret = true;
158 switch (_kind) {
159 case WEAK:
160 // set item dependencies to weak
161 resolver.addWeak( _item );
162 break;
163 default:
164 ERR << "No valid InjectSolutionAction kind found" << endl;
165 ret = false;
166 break;
167 }
168 return ret;
169 }
170
171} // namespace zypp::solver::detail
String related utilities and Regular expression matching.
std::ostream & operator<<(std::ostream &str, const SolutionActionList &actionlist)
std::list< SolutionAction_Ptr > SolutionActionList
Definition Types.h:48
Resolver ResolverInternal
Preferred name in API.
Definition Types.h:39
#define ERR
Definition Logger.h:102
#define IMPL_PTR_TYPE(NAME)