00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <map>
00023 #include <sstream>
00024
00025 #include "zypp/solver/detail/ResolverInfo.h"
00026 #include "zypp/Source.h"
00027 #include "zypp/Capability.h"
00028 #include "zypp/base/String.h"
00029 #include "zypp/base/Gettext.h"
00030 #include "zypp/base/Logger.h"
00031
00033 namespace zypp
00034 {
00035
00036 namespace solver
00037 {
00038
00039 namespace detail
00040 {
00041
00042 using namespace std;
00043
00044 IMPL_PTR_TYPE(ResolverInfo);
00045
00046
00047
00048 #define RIT(x) RESOLVER_INFO_TYPE_ ## x, #x
00049 static struct {
00050 ResolverInfoType type;
00051 const char *typestr;
00052 const char *str;
00053 } type_str_table[] = {
00054 { RIT(NEEDED_BY), "needed_by" },
00055 { RIT(CONFLICTS_WITH), "conflicts_with" },
00056 { RIT(OBSOLETES), "obsoletes" },
00057 { RIT(DEPENDS_ON), "depended_on" },
00058 { RIT(CHILD_OF), "child_of" },
00059 { RIT(MISSING_REQ), "missing_req" },
00060
00061 { RIT(INVALID_SOLUTION), "Marking this resolution attempt as invalid" },
00062 { RIT(UNINSTALLABLE), "Marking p as uninstallable" },
00063 { RIT(REJECT_INSTALL), "p is scheduled to be installed, but this is not possible because of dependency problems." },
00064 { RIT(INSTALL_TO_BE_UNINSTALLED), "Can't install p since it is already marked as needing to be uninstalled" },
00065 { RIT(INSTALL_UNNEEDED), "Can't install p since it is does not apply to this system." },
00066 { RIT(INSTALL_PARALLEL), "Can't install p, since a resolvable of the same name is already marked as needing to be installed." },
00067 { RIT(INCOMPLETES), "This would invalidate p" },
00068
00069 { RIT(ESTABLISHING), "Establishing p" },
00070
00071 { RIT(INSTALLING), "Installing p" },
00072 { RIT(UPDATING), "Updating p" },
00073 { RIT(SKIPPING), "Skipping p, already installed" },
00074
00075 { RIT(NO_OTHER_PROVIDER), "There are no alternative installed providers of c [for p]" },
00076 { RIT(NO_PROVIDER), "There are no installable providers of c [for p]" },
00077 { RIT(NO_UPGRADE), "Upgrade to q to avoid removing p is not possible." },
00078 { RIT(UNINSTALL_PROVIDER), "p provides c but is scheduled to be uninstalled" },
00079 { RIT(KEEP_PROVIDER), "p provides c but is scheduled to be kept" },
00080 { RIT(PARALLEL_PROVIDER), "p provides c but another version is already installed" },
00081 { RIT(NOT_INSTALLABLE_PROVIDER), "p provides c but is uninstallable" },
00082 { RIT(LOCKED_PROVIDER), "p provides c but is locked" },
00083 { RIT(OTHER_ARCH_PROVIDER), "p provides c but has other architecture" },
00084 { RIT(CANT_SATISFY), "Can't satisfy requirement c" },
00085
00086 { RIT(UNINSTALL_TO_BE_INSTALLED), "p is to-be-installed, so it won't be unlinked." },
00087 { RIT(UNINSTALL_INSTALLED), "p is required by installed, so it won't be unlinked." },
00088 { RIT(UNINSTALL_LOCKED), "cant uninstall, its locked" },
00089
00090 { RIT(CONFLICT_CANT_INSTALL), "to-be-installed p conflicts with q due to c" },
00091 { RIT(CONFLICT_UNINSTALLABLE), "uninstalled p is marked uninstallable it conflicts [with q] due to c" },
00092 { RIT(INVALID), "invalid" },
00093 { RIT(INVALID), NULL }
00094 };
00095 #undef RIT
00096
00097 static const char *
00098 info_type_to_string (ResolverInfoType type)
00099 {
00100 int i;
00101
00102 for (i = 0; type_str_table[i].str != NULL; ++i) {
00103 if (type == type_str_table[i].type)
00104 return type_str_table[i].typestr;
00105 }
00106
00107 return "?ResolverInfoType?";
00108 }
00109
00110
00111 static const char *
00112 info_type_to_message (ResolverInfoType type)
00113 {
00114 int i;
00115
00116 for (i = 0; type_str_table[i].str != NULL; ++i) {
00117 if (type == type_str_table[i].type)
00118 return type_str_table[i].str;
00119 }
00120
00121 return "?ResolverInfoType?";
00122 }
00123
00124
00125 ResolverInfoType
00126 resolver_info_type_from_string (const char *str)
00127 {
00128 int i;
00129
00130 if (str == NULL) return RESOLVER_INFO_TYPE_INVALID;
00131
00132 for (i = 0; type_str_table[i].str != NULL; ++i) {
00133 if (strcasecmp (str, type_str_table[i].str) == 0)
00134 return type_str_table[i].type;
00135 }
00136
00137 return RESOLVER_INFO_TYPE_INVALID;
00138 }
00139
00140 string
00141 ResolverInfo::toString (PoolItem_Ref item)
00142 {
00143 ostringstream os;
00144 if (!item) return "";
00145
00146 if (item->kind() != ResTraits<zypp::Package>::kind)
00147 os << item->kind() << ':';
00148 os << item->name() << '-' << item->edition();
00149 if (item->arch() != "") {
00150 os << '.' << item->arch();
00151 }
00152 Source_Ref s = item->source();
00153 if (s) {
00154 string alias = s.alias();
00155 if (!alias.empty()
00156 && alias != "@system")
00157 {
00158 os << '[' << s.alias() << ']';
00159 }
00160 }
00161 return os.str();
00162 }
00163
00164
00165 string
00166 ResolverInfo::toString (const Capability & capability)
00167 {
00168 ostringstream os;
00169 os << capability.asString();
00170 return os.str();
00171 }
00172
00173 string
00174 ResolverInfo::message( ) const
00175 {
00176 return string(info_type_to_message(_type)) + " " + toString(_affected);
00177 }
00178
00179
00180 std::ostream &
00181 ResolverInfo::dumpOn( std::ostream & os ) const
00182 {
00183 os << "ResolverInfo<";
00184 os << info_type_to_string (_type);
00185 os << "> ";
00186
00187 if (_affected) {
00188 os << toString (_affected);
00189 }
00190
00191 if (_error) os << " " << _(" Error!");
00192 if (_important) os << " " << _(" Important!");
00193
00194 return os;
00195 }
00196
00197
00198
00199 ResolverInfo::ResolverInfo (ResolverInfoType type, PoolItem_Ref item, int priority)
00200 : _type (type)
00201 , _affected (item)
00202 , _priority (priority)
00203 , _error (false)
00204 , _important (false)
00205 {
00206 _XDEBUG(*this);
00207 }
00208
00209
00210 ResolverInfo::~ResolverInfo()
00211 {
00212 }
00213
00214
00215
00216 bool
00217 ResolverInfo::merge (ResolverInfo_Ptr to_be_merged)
00218 {
00219 if (to_be_merged == NULL) return false;
00220
00221 if (_type != to_be_merged->_type
00222 || _affected != to_be_merged->_affected
00223 || _error != to_be_merged->_error) {
00224 return false;
00225 }
00226
00227 return true;
00228 }
00229
00230 void
00231 ResolverInfo::copy (ResolverInfo_constPtr from)
00232 {
00233 _error = from->_error;
00234 _important = from->_important;
00235 }
00236
00237
00238 ResolverInfo_Ptr
00239 ResolverInfo::copy (void) const
00240 {
00241 ResolverInfo_Ptr cpy = new ResolverInfo(_type, _affected, _priority);
00242
00243 cpy->copy (this);
00244
00245 return cpy;
00246 }
00247
00248
00249
00250
00251 bool
00252 ResolverInfo::isAbout (PoolItem_Ref item) const
00253 {
00254 if (!_affected)
00255 return false;
00256
00257 return _affected->name() == item->name();
00258 }
00259
00261 };
00264 };
00267 };
00269