From 72701f91df0863b08e4f1df88b628f14a5376f46 Mon Sep 17 00:00:00 2001 From: Klaus Kaempf Date: Thu, 26 Jan 2006 11:15:17 +0000 Subject: [PATCH] backup --- zypp/solver/detail/QueueItemInstall.cc | 455 +++++++++++++++++---------------- 1 file changed, 241 insertions(+), 214 deletions(-) diff --git a/zypp/solver/detail/QueueItemInstall.cc b/zypp/solver/detail/QueueItemInstall.cc index 42aea6a..65f025d 100644 --- a/zypp/solver/detail/QueueItemInstall.cc +++ b/zypp/solver/detail/QueueItemInstall.cc @@ -18,12 +18,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307, USA. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "zypp/solver/temporary/ResItem.h" -#include "zypp/solver/temporary/World.h" #include "zypp/solver/detail/QueueItemInstall.h" #include "zypp/solver/detail/QueueItemEstablish.h" @@ -35,7 +29,8 @@ #include "zypp/solver/detail/ResolverInfoConflictsWith.h" #include "zypp/solver/detail/ResolverInfoMisc.h" #include "zypp/solver/detail/ResolverInfoNeededBy.h" -#include "zypp/solver/detail/ResItemAndDependency.h" +#include "zypp/solver/detail/Helper.h" + #include "zypp/CapFactory.h" #include "zypp/CapSet.h" #include "zypp/base/Logger.h" @@ -58,71 +53,52 @@ IMPL_PTR_TYPE(QueueItemInstall); //--------------------------------------------------------------------------- -string -QueueItemInstall::asString ( void ) const -{ - return toString (*this); -} - - -string -QueueItemInstall::toString ( const QueueItemInstall & item) -{ - string ret = "[Install: "; - ret += item._resItem->asString(); - if (item._upgrades != NULL) { - ret += ", Upgrades "; - ret += item._upgrades->asString(); - } - if (!item._deps_satisfied_by_this_install.empty()) { - ret += ", Satisfies ["; - for (CapSet::const_iterator iter = item._deps_satisfied_by_this_install.begin(); - iter != item._deps_satisfied_by_this_install.end(); iter++) { - if (iter != item._deps_satisfied_by_this_install.begin()) ret += ", "; - ret += (*iter).asString(); - } - ret += "]"; - } - if (!item._needed_by.empty()) { - ret += ", Needed by "; - ret += ResItem::toString(item._needed_by); - } - if (item._explicitly_requested) ret += ", Explicit !"; - ret += "]"; - return ret; -} - - -ostream & -QueueItemInstall::dumpOn( ostream & str ) const -{ - str << asString(); - return str; -} - - ostream& operator<<( ostream& os, const QueueItemInstall & item) { - return os << item.asString(); + os << "[Install: "; + os << item._item->asString(); + if (item._upgrades != NULL) { + os << ", Upgrades "; + os << item._upgrades->asString(); + } + if (!item._deps_satisfied_by_this_install.empty()) { + os << ", Satisfies ["; + for (CapSet::const_iterator iter = item._deps_satisfied_by_this_install.begin(); + iter != item._deps_satisfied_by_this_install.end(); iter++) + { + if (iter != item._deps_satisfied_by_this_install.begin()) os << ", "; + os << (*iter).asString(); + } + os << "]"; + } + if (!item._needed_by.empty()) { + os << ", Needed by "; + os << ResItem::toString(item._needed_by); + } + if (item._explicitly_requested) os << ", Explicit !"; + os << "]"; + return os; } //--------------------------------------------------------------------------- -QueueItemInstall::QueueItemInstall (World_Ptr world, ResItem_constPtr resItem) - : QueueItem (QUEUE_ITEM_TYPE_INSTALL, world) - , _resItem (resItem) - , _channel_priority (0) - , _other_penalty (0) - , _explicitly_requested (false) +QueueItemInstall::QueueItemInstall (const ResPool *pool, PoolItem *item) + : QueueItem (QUEUE_ITEM_TYPE_INSTALL, pool) + , _item (item) + , _channel_priority (0) + , _other_penalty (0) + , _explicitly_requested (false) { - ResItem_constPtr upgrades = world->findInstalledResItem (resItem); - _DBG("RC_SPEW") << "QueueItemInstall::QueueItemInstall(" << resItem->asString() << ") upgrades " - << ((upgrades!=NULL) ? upgrades->asString() : "nothing") << endl; - if (upgrades - && ! (upgrades->equals (resItem))) { - setUpgrades(upgrades); - } + PoolItem upgrades = Helper::findInstalledItem (item); + + DBG << "QueueItemInstall::QueueItemInstall(" << item << ") upgrades " + << ((upgrades!=PoolItem()) ? upgrades : "nothing") << endl; + if (upgrades!=PoolItem() + && ! (upgrades->equals (item))) + { + setUpgrades(upgrades); + } } @@ -135,230 +111,276 @@ QueueItemInstall::~QueueItemInstall() bool QueueItemInstall::isSatisfied (ResolverContext_Ptr context) const { - return context->resItemIsPresent (_resItem); + return context->isPresent (_item); } //--------------------------------------------------------------------------- -// Handle system resItem's that conflict with us -> uninstall them +// Handle system item's that conflict with us -> uninstall them -static bool -build_conflict_list (ResItem_constPtr resItem, const Capability & dep, void *data) +struct BuildConflictList : public resfilter::OnCapMatchCallbackFunctor { - CResItemList *rl = (CResItemList *)data; - rl->push_front (resItem); + PoolItemList items; + + bool operator()( PoolItem provider, const Capability & match ) const + { + // Untill we can pass the functor by reference to algorithms. + return const_cast(*this).fake( provider, match ); + } + bool fake( PoolItem provider, const Capability & match ) + { + items.push_front (provider); return true; + } } -// Handle resItems which freshen us -> re-establish them -typedef struct { - World_Ptr world; - QueueItemList *qil; -} EstablishFreshensInfo; +//--------------------------------------------------------------------------- + +// Handle items which freshen us -> re-establish them -static bool -establish_freshens_cb (ResItem_constPtr resItem, const Capability & dep, void *data) +struct EstablishFreshens : public resfilter::OnCapMatchCallbackFunctor { - _DBG("RC_SPEW") << "establish_freshens_cb (" << resItem << ", " << dep << ")" << endl; - EstablishFreshensInfo *info = (EstablishFreshensInfo *)data; + const ResPool *pool; + QueueItemList & qil; - QueueItemEstablish_Ptr establish_item = new QueueItemEstablish (info->world, resItem); - info->qil->push_front (establish_item); - return true; + EstablishFreshens (const ResPool *p, QueueItemList &l) + : pool (p) + , qli (l) + { } + + + // provider has a freshens on a just to-be-installed item + // re-establish provider, maybe its incomplete now + + bool operator()( PoolItem provider, const Capability & match ) const + { + // Untill we can pass the functor by reference to algorithms. + return const_cast(*this).fake( provider, match ); + } + bool fake( PoolItem provider, const Capability & match ) + { + DBG << "EstablishFreshens (" << provider << ", " << math << ")" << endl; + + QueueItemEstablish_Ptr establish_item = new QueueItemEstablish (pool, provider); + qil.push_front (provider); + return true; + } } +//--------------------------------------------------------------------------------------- + bool QueueItemInstall::process (ResolverContext_Ptr context, QueueItemList & qil) { - _DBG("RC_SPEW") << "QueueItemInstall::process(" << this->asString() << ")" << endl; + DBG << "QueueItemInstall::process(" << this->asString() << ")" << endl; - ResItem_constPtr resItem = _resItem; - string res_name = resItem->asString(); - string msg; - ResItemStatus status = context->getStatus (resItem); + ResItemStatus status = _item.status(); - /* If we are trying to upgrade resItem A with resItem B and they both have the - same version number, do nothing. This shouldn't happen in general with - red-carpet, but can come up with the installer & autopull. */ + /* If we are trying to upgrade item A with item B and they both have the + same version number, do nothing. This shouldn't happen in general with + zypp, but can come up with the installer & autopull. */ - if (_upgrades - && _resItem->equals (_upgrades)) { - ResolverInfo_Ptr info; + if (*_item == *_upgrades) + { + ResolverInfo_Ptr info; - _DBG("RC_SPEW") << "upgrades equal resItem, skipping" << endl; + DBG << "install upgrades itself, skipping" << endl; - info = new ResolverInfoMisc (RESOLVER_INFO_TYPE_SKIPPING, _resItem, RESOLVER_INFO_PRIORITY_VERBOSE); - context->addInfo (info); - goto finished; - } + info = new ResolverInfoMisc (RESOLVER_INFO_TYPE_SKIPPING, _item, RESOLVER_INFO_PRIORITY_VERBOSE); + context->addInfo (info); + goto finished; + } - // check if this install is still needed - // (maybe other resolver processing made this install obsolete + // check if this install is still needed + // (maybe other resolver processing made this install obsolete - if (!_needed_by.empty()) { - bool still_needed = false; + if (!_needed_by.empty()) { + bool still_needed = false; - _DBG("RC_SPEW") << "still needed " << endl; + DBG << "still needed " << endl; - for (CResItemList::const_iterator iter = _needed_by.begin(); iter != _needed_by.end() && !still_needed; iter++) { - ResItemStatus status = context->getStatus (*iter); - _DBG("RC_SPEW") << "by: [status: " << ResolverContext::toString(status) << "] " << (*iter)->asString() << endl; - if (! resItem_status_is_to_be_uninstalled (status)) { - still_needed = true; - } + for (PoolItemList::const_iterator iter = _needed_by.begin(); iter != _needed_by.end() && !still_needed; ++iter) { + ResItemStatus status = iter->status(); + DBG << "by: [status: " << status << "] " << *iter << endl; + if (! item_status_is_to_be_uninstalled (status)) { + still_needed = true; } - - if (! still_needed) - goto finished; } - /* If we are in verify mode and this install is about to fail, don't let it happen... + if (! still_needed) + goto finished; + } + + /* If we are in verify mode and this install is about to fail, don't let it happen... instead, we try to back out of the install by removing whatever it was that needed this. */ - if (context->verifying() - && resItem_status_is_to_be_uninstalled (context->getStatus (resItem)) - && !_needed_by.empty()) { + if (context->verifying() + && item_status_is_to_be_uninstalled (_item.status())) + && !_needed_by.empty()) { - QueueItemUninstall_Ptr uninstall_item; - - for (CResItemList::const_iterator iter = _needed_by.begin(); iter != _needed_by.end(); iter++) { - uninstall_item = new QueueItemUninstall (world(), *iter, QueueItemUninstall::BACKOUT); - qil.push_front (uninstall_item); - } + QueueItemUninstall_Ptr uninstall_item; - goto finished; + for (PoolItemList::const_iterator iter = _needed_by.begin(); iter != _needed_by.end(); iter++) { + uninstall_item = new QueueItemUninstall (pool(), *iter, QueueItemUninstall::BACKOUT); + qil.push_front (uninstall_item); } - // if this install upgrades an installed resolvable, explicitly uninstall this one - // in order to ensure that all dependencies are still met after the upgrade + goto finished; + } - if (_upgrades == NULL) { + // if this install upgrades an installed resolvable, explicitly uninstall this one + // in order to ensure that all dependencies are still met after the upgrade - _DBG("RC_SPEW") << "simple install of " << resItem->asString(true) << endl; +#warning item default + if (*_upgrades == NULL) { - context->installResItem (resItem, context->verifying() /* is_soft */, _other_penalty); + DBG << "simple install of " << _item << endl; + context->install (_item, context->verifying() /* is_soft */, _other_penalty); - } else { + } else { - QueueItemUninstall_Ptr uninstall_item; + QueueItemUninstall_Ptr uninstall_item; - _DBG("RC_SPEW") << "upgrade install of " << resItem->asString() << endl; + DBG << "upgrade install of " << _item << endl; - context->upgradeResItem (resItem, _upgrades, context->verifying() /* is_soft */, _other_penalty); + context->upgrade (_item, _upgrades, context->verifying() /* is_soft */, _other_penalty); - uninstall_item = new QueueItemUninstall (world(), _upgrades, QueueItemUninstall::UPGRADE); - uninstall_item->setUpgradedTo (resItem); + // the upgrade will uninstall the installed one, take care of this - if (_explicitly_requested) - uninstall_item->setExplicitlyRequested (); + uninstall_item = new QueueItemUninstall (pool(), _upgrades, QueueItemUninstall::UPGRADE); + uninstall_item->setUpgradedTo (_item); - qil.push_front (uninstall_item); - } + if (_explicitly_requested) + uninstall_item->setExplicitlyRequested (); - /* Log which resItem need this install */ + qil.push_front (uninstall_item); - if (!_needed_by.empty()) { - ResolverInfoNeededBy_Ptr info; + } - info = new ResolverInfoNeededBy (resItem); - info->addRelatedResItemList (_needed_by); - context->addInfo (info); - } + /* Log which item need this install */ - // we're done if this isn't currently uninstalled or incomplete + if (!_needed_by.empty()) { - if (! (status == RESOLVABLE_STATUS_UNINSTALLED - || status == RESOLVABLE_STATUS_TO_BE_UNINSTALLED_DUE_TO_UNLINK - || resItem_status_is_incomplete (status) - || resItem_status_is_satisfied (status))) { - goto finished; - } + ResolverInfoNeededBy_Ptr info; + + info = new ResolverInfoNeededBy (_item); + info->addRelatedResItemList (_needed_by); + context->addInfo (info); + } - { // just a block for local initializers, the goto above makes this necessary + // we're done if this isn't currently uninstalled or incomplete + + if (! (status == RESOLVABLE_STATUS_UNINSTALLED + || status == RESOLVABLE_STATUS_TO_BE_UNINSTALLED_DUE_TO_UNLINK + || item_status_is_incomplete (status) + || item_status_is_satisfied (status))) + { + goto finished; + } + + { // just a block for local initializers, the goto above makes this necessary ResolverInfoMisc_Ptr misc_info; +#warning PoolItem default + if (*_upgrades) { - if (_upgrades != NULL) { - misc_info = new ResolverInfoMisc (RESOLVER_INFO_TYPE_UPDATING, resItem, RESOLVER_INFO_PRIORITY_VERBOSE); + misc_info = new ResolverInfoMisc (RESOLVER_INFO_TYPE_UPDATING, _item, RESOLVER_INFO_PRIORITY_VERBOSE); misc_info->setOtherResItem (_upgrades); -cerr << "Updating " << _upgrades->asString() << " to " << resItem->asString() << endl; + } else { - misc_info = new ResolverInfoMisc (RESOLVER_INFO_TYPE_INSTALLING, resItem, RESOLVER_INFO_PRIORITY_VERBOSE); + + misc_info = new ResolverInfoMisc (RESOLVER_INFO_TYPE_INSTALLING, _item, RESOLVER_INFO_PRIORITY_VERBOSE); + } context->addInfo (misc_info); logInfo (context); - /* Construct require items for each of the resItem's requires that is still unsatisfied. */ + /* Construct require items for each of the item's requires that is still unsatisfied. */ + + CapSet caps; - CapSet deps; + caps = _item->dep (Dep::REQUIRES); - deps = resItem->requires(); + for (CapSet::const_iterator iter = caps.begin(); iter != caps.end(); iter++) { - for (CapSet::const_iterator iter = deps.begin(); iter != deps.end(); iter++) { - const Capability dep = *iter; - _DBG("RC_SPEW") << "this requires " << dep.asString() << endl; - if (!context->requirementIsMet (dep)) { - _DBG("RC_SPEW") << "this requires " << dep.asString() << endl; - QueueItemRequire_Ptr req_item = new QueueItemRequire (world(), dep); - req_item->addResItem (resItem); + const Capability cap = *iter; + DBG << "this requires " << cap << endl; + + if (!context->requirementIsMet (cap)) { + DBG << "this requirement is still unfulfilled" << endl; + QueueItemRequire_Ptr req_item = new QueueItemRequire (pool(), cap); + req_item->addResItem (item); qil.push_front (req_item); } + } - /* Construct conflict items for each of the resItem's conflicts. */ + /* Construct conflict items for each of the item's conflicts. */ - deps = resItem->conflicts(); - for (CapSet::const_iterator iter = deps.begin(); iter != deps.end(); iter++) { - const Capability dep = *iter; - _DBG("RC_SPEW") << "this conflicts with '" << dep.asString() << "'" << endl; - QueueItemConflict_Ptr conflict_item = new QueueItemConflict (world(), dep, resItem); + caps = item->dep (Dep::CONFLICTS); + for (CapSet::const_iterator iter = caps.begin(); iter != caps.end(); iter++) { + + const Capability cap = *iter; + DBG << "this conflicts with '" << cap << "'" << endl; + QueueItemConflict_Ptr conflict_item = new QueueItemConflict (pool(), cap, item); qil.push_front (conflict_item); + } - /* Construct conflict items for each of the resItem's obsoletes. */ + /* Construct conflict items for each of the item's obsoletes. */ - deps = resItem->obsoletes(); - for (CapSet::const_iterator iter = deps.begin(); iter != deps.end(); iter++) { - const Capability dep = *iter; - _DBG("RC_SPEW") << "this obsoletes " << dep.asString() << endl; - QueueItemConflict_Ptr conflict_item = new QueueItemConflict (world(), dep, resItem); + caps = item->dep (Dep::OBSOLETES); + for (CapSet::const_iterator iter = caps.begin(); iter != caps.end(); iter++) { + + const Capability cap = *iter; + DBG << "this obsoletes " << dep << endl; + QueueItemConflict_Ptr conflict_item = new QueueItemConflict (pool(), cap, item); conflict_item->setActuallyAnObsolete(); qil.push_front (conflict_item); + } - /* Construct uninstall items for system resItem's that conflict with us. */ + /* Construct uninstall items for system item's that conflict with us. */ - CResItemList conflicts; - deps = resItem->provides(); - for (CapSet::const_iterator iter = deps.begin(); iter != deps.end(); iter++) { - const Capability dep = *iter; - world()->foreachConflictingResItem (dep, build_conflict_list, &conflicts); + BuildConflictList conflicts; + caps = item->dep (Dep::PROVIDES); + for (CapSet::const_iterator iter = caps.begin(); iter != caps.end(); iter++) { + const Capability cap = *iter; + + // pool()->foreachConflictingResItem (dep, build_conflict_list, &conflicts); + + Dep dep( Dep::CONFLICTS); + invokeOnEach( pool()->byCapabilityIndexBegin( cap.index(), dep ), // begin() + pool()->byCapabilityIndexEnd( cap.index(), dep ), // end() + resfilter::callOnCapMatchIn( dep, cap, conflicts) ); } - for (CResItemList::const_iterator iter = conflicts.begin(); iter != conflicts.end(); iter++) { - ResItem_constPtr conflicting_resItem = *iter; + for (PoolItemList::const_iterator iter = conflicts.items.begin(); iter != conflicts.items.end(); ++iter) { + + PoolItem conflicting_item = *iter; ResolverInfo_Ptr log_info; QueueItemUninstall_Ptr uninstall_item; /* Check to see if we conflict with ourself and don't create * an uninstall item for it if we do. This is Debian's way of - * saying that one and only one resItem with this provide may + * saying that one and only one item with this provide may * exist on the system at a time. */ - if (conflicting_resItem->equals (resItem)) { + + if (*conflicting_item == *_item) { continue; } - _DBG("RC_SPEW") << "because: '" << conflicting_resItem->asString(true) << "'" << endl; + DBG << "because: '" << conflicting_item->asString(true) << "'" << endl; - uninstall_item = new QueueItemUninstall (world(), conflicting_resItem, QueueItemUninstall::CONFLICT); + uninstall_item = new QueueItemUninstall (pool(), conflicting_item, QueueItemUninstall::CONFLICT); uninstall_item->setDueToConflict (); - log_info = new ResolverInfoConflictsWith (conflicting_resItem, resItem); + log_info = new ResolverInfoConflictsWith (conflicting_item, _item); uninstall_item->addInfo (log_info); qil.push_front (uninstall_item); } @@ -366,44 +388,49 @@ cerr << "Updating " << _upgrades->asString() << " to " << resItem->asString() << /* Construct establish items for each of those which freshen this resolvable. */ - EstablishFreshensInfo info = { world(), &qil }; + EstablishFreshens info( pool(), qil ); + CapFactory factory; - Capability cap = factory.parse (resItem->kind(), resItem->name(), Rel::EQ, resItem->edition()); - world()->foreachFresheningResItem (cap, establish_freshens_cb, &info); + Capability cap = factory.parse (_item->kind(), _item->name(), Rel::EQ, _item->edition()); + // pool ()->foreachFresheningResItem (cap, establish_freshens_cb, &info); + Dep dep( Dep::FRESHENS); + invokeOnEach( pool()->byCapabilityIndexBegin( cap.index(), dep ), // begin() + pool()->byCapabilityIndexEnd( cap.index(), dep ), // end() + resfilter::callOnCapMatchIn( dep, cap, info) ); - } + } // end of block finished: - return true; + return true; } QueueItem_Ptr QueueItemInstall::copy (void) const { - QueueItemInstall_Ptr new_install = new QueueItemInstall (world(), _resItem); - new_install->QueueItem::copy(this); + QueueItemInstall_Ptr new_install = new QueueItemInstall (pool(), _item); + new_install->QueueItem::copy(this); - new_install->_upgrades = _upgrades; - new_install->_deps_satisfied_by_this_install = CapSet(_deps_satisfied_by_this_install.begin(), _deps_satisfied_by_this_install.end()); - new_install->_needed_by = CResItemList (_needed_by.begin(), _needed_by.end()); - new_install->_channel_priority = _channel_priority; - new_install->_other_penalty = _other_penalty; - new_install->_explicitly_requested = _explicitly_requested; + new_install->_upgrades = _upgrades; + new_install->_deps_satisfied_by_this_install = CapSet(_deps_satisfied_by_this_install.begin(), _deps_satisfied_by_this_install.end()); + new_install->_needed_by = PoolItemList (_needed_by.begin(), _needed_by.end()); + new_install->_channel_priority = _channel_priority; + new_install->_other_penalty = _other_penalty; + new_install->_explicitly_requested = _explicitly_requested; - return new_install; + return new_install; } int QueueItemInstall::cmp (QueueItem_constPtr item) const { - int cmp = this->compare (item); - if (cmp != 0) - return cmp; - QueueItemInstall_constPtr install = dynamic_pointer_cast(item); - return ResItem::compare (_resItem, install->_resItem); + int cmp = this->compare (item); + if (cmp != 0) + return cmp; + QueueItemInstall_constPtr install = dynamic_pointer_cast(item); + return ResItem::compare (_item, install->_item); } //--------------------------------------------------------------------------- @@ -411,14 +438,14 @@ QueueItemInstall::cmp (QueueItem_constPtr item) const void QueueItemInstall::addDependency (const Capability & dep) { - _deps_satisfied_by_this_install.insert (dep); + _deps_satisfied_by_this_install.insert (dep); } void -QueueItemInstall::addNeededBy (ResItem_constPtr resItem) +QueueItemInstall::addNeededBy (PoolItem item) { - _needed_by.push_front (resItem); + _needed_by.push_front (item); } /////////////////////////////////////////////////////////////////// -- 2.7.4