00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "zypp/solver/detail/Resolver.h"
00025 #include "zypp/solver/detail/SolutionAction.h"
00026 #include "zypp/CapSet.h"
00027 #include "zypp/base/Logger.h"
00028 #include "zypp/Dependencies.h"
00029
00030
00032 namespace zypp
00033 {
00034
00035 namespace solver
00036 {
00037
00038 namespace detail
00039 {
00040
00041 using namespace std;
00042
00043 IMPL_PTR_TYPE(SolutionAction);
00044 IMPL_PTR_TYPE(TransactionSolutionAction);
00045 IMPL_PTR_TYPE(InjectSolutionAction);
00046
00047
00048
00049 SolutionAction::SolutionAction()
00050 {
00051 }
00052
00053
00054 SolutionAction::~SolutionAction()
00055 {
00056 }
00057
00058
00059
00060
00061 ostream &
00062 TransactionSolutionAction::dumpOn( ostream& os) const
00063 {
00064 os << "TransactionSolutionAction: ";
00065 switch (_action) {
00066 case KEEP: os << "Keep"; break;
00067 case INSTALL: os << "Install"; break;
00068 case REMOVE: os << "Remove"; break;
00069 case UNLOCK: os << "Unlock"; break;
00070 }
00071 os << " ";
00072 os << _item;
00073 os << endl;
00074 return os;
00075 }
00076
00077
00078 ostream&
00079 operator<<( ostream& os, const SolutionActionList & actionlist)
00080 {
00081 for (SolutionActionList::const_iterator iter = actionlist.begin(); iter != actionlist.end(); ++iter) {
00082 os << *(*iter);
00083 os << endl;
00084 }
00085 return os;
00086 }
00087
00088
00089 ostream&
00090 operator<<( ostream& os, const CSolutionActionList & actionlist)
00091 {
00092 for (CSolutionActionList::const_iterator iter = actionlist.begin(); iter != actionlist.end(); ++iter) {
00093 os << *(*iter);
00094 os << endl;
00095 }
00096 return os;
00097 }
00098
00099
00100
00101 ostream &
00102 InjectSolutionAction::dumpOn( ostream& os ) const
00103 {
00104 os << "InjectSolutionAction: ";
00105 os << _capability;
00106 os << ", ";
00107 switch (_kind) {
00108 case REQUIRES: os << "Requires"; break;
00109 case CONFLICTS: os << "Conflicts"; break;
00110 case OBSOLETES: os << "Obsoletes"; break;
00111 case INSTALLED: os << "Installed"; break;
00112 case ARCHITECTURE: os << "Architecture"; break;
00113 default: os << "Wrong kind"; break;
00114 }
00115 os << " ";
00116 os << _item;
00117 os << endl;
00118 return os;
00119 }
00120
00121
00122
00123
00124 ostream &
00125 SolutionAction::dumpOn( std::ostream & os ) const
00126 {
00127 os << "SolutionAction<";
00128 os << "not specified";
00129 os << "> ";
00130 return os;
00131 }
00132
00133
00134 bool
00135 TransactionSolutionAction::execute(Resolver & resolver) const
00136 {
00137 bool ret = true;
00138 switch (action()) {
00139 case KEEP:
00140 resolver.addIgnoreInstalledItem( _item );
00141
00142 case INSTALL:
00143 if (_item.status().isToBeUninstalled())
00144 ret = _item.status().setTransact (false, ResStatus::USER);
00145 else
00146 _item.status().setToBeInstalled (ResStatus::USER);
00147 break;
00148 case REMOVE:
00149 if (_item.status().isToBeInstalled()) {
00150 _item.status().setTransact (false,ResStatus::USER);
00151 _item.status().setLock (true,ResStatus::USER);
00152 } else if (_item.status().isInstalled())
00153 _item.status().setToBeUninstalled (ResStatus::USER);
00154 else
00155 _item.status().setLock (true,ResStatus::USER);
00156 break;
00157 case UNLOCK:
00158 ret = _item.status().setLock (false, ResStatus::USER);
00159 if (!ret) ERR << "Cannot unlock " << _item << endl;
00160 break;
00161 default:
00162 ERR << "Wrong TransactionKind" << endl;
00163 ret = false;
00164 }
00165 return ret;
00166 }
00167
00168 bool
00169 InjectSolutionAction::execute(Resolver & resolver) const
00170 {
00171 Dependencies dependencies = _item.resolvable()->deps();
00172 CapSet depList = dependencies[Dep::CONFLICTS];
00173 switch (_kind) {
00174 case CONFLICTS:
00175
00176 if (depList.find(_capability) != depList.end())
00177 {
00178 resolver.addIgnoreConflict (_item, _capability);
00179 }
00180 dependencies = _otherItem.resolvable()->deps();
00181 depList = dependencies[Dep::CONFLICTS];
00182 if (depList.find(_capability) != depList.end())
00183 {
00184 resolver.addIgnoreConflict (_otherItem, _capability);
00185 }
00186 break;
00187 case REQUIRES:
00188
00189 resolver.addIgnoreRequires (_item, _capability);
00190 break;
00191 case ARCHITECTURE:
00192
00193 resolver.addIgnoreArchitectureItem (_item);
00194 break;
00195 case OBSOLETES:
00196
00197 resolver.addIgnoreObsoletes (_otherItem, _capability);
00198 break;
00199 case INSTALLED:
00200
00201 resolver.addIgnoreInstalledItem (_item);
00202 resolver.addIgnoreInstalledItem (_otherItem);
00203 break;
00204 default:
00205 ERR << "No valid InjectSolutionAction kind found" << endl;
00206 return false;
00207 }
00208
00209 return true;
00210 }
00211
00213 };
00216 };
00219 };