QueueItemEstablish.cc

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* QueueItemEstablish.cc
00003  *
00004  * Copyright (C) 2000-2002 Ximian, Inc.
00005  * Copyright (C) 2005 SUSE Linux Products GmbH
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License,
00009  * version 2, as published by the Free Software Foundation.
00010  *
00011  * This program is distributed in the hope that it will be useful, but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019  * 02111-1307, USA.
00020  */
00021 
00022 #include "zypp/solver/detail/Types.h"
00023 
00024 #include "zypp/solver/detail/QueueItemEstablish.h"
00025 #include "zypp/solver/detail/QueueItemInstall.h"
00026 #include "zypp/solver/detail/QueueItemRequire.h"
00027 #include "zypp/solver/detail/QueueItemConflict.h"
00028 #include "zypp/solver/detail/QueueItem.h"
00029 #include "zypp/solver/detail/Helper.h"
00030 #include "zypp/solver/detail/ResolverContext.h"
00031 #include "zypp/solver/detail/ResolverInfoConflictsWith.h"
00032 #include "zypp/solver/detail/ResolverInfoNeededBy.h"
00033 #include "zypp/solver/detail/ResolverInfoMisc.h"
00034 
00035 #include "zypp/CapSet.h"
00036 #include "zypp/base/Logger.h"
00037 #include "zypp/base/String.h"
00038 #include "zypp/base/Gettext.h"
00039 
00041 namespace zypp
00042 { 
00043 
00044   namespace solver
00045   { 
00046 
00047     namespace detail
00048     { 
00049 
00050 using namespace std;
00051 
00052 IMPL_PTR_TYPE(QueueItemEstablish);
00053 
00054 //---------------------------------------------------------------------------
00055 
00056 std::ostream &
00057 QueueItemEstablish::dumpOn( std::ostream & os ) const
00058 {
00059     os <<"[Establish: ";
00060     os << _item;
00061     if (_explicitly_requested) os << ", Explicit !";
00062     os << "]";
00063     return os;
00064 }
00065 
00066 //---------------------------------------------------------------------------
00067 
00068 QueueItemEstablish::QueueItemEstablish (const ResPool & pool, PoolItem_Ref item, bool soft)
00069     : QueueItem (QUEUE_ITEM_TYPE_ESTABLISH, pool)
00070     , _item(item)
00071     , _soft(soft)
00072     , _channel_priority (0)
00073     , _other_penalty (0)
00074     , _explicitly_requested (false)
00075 {
00076     _XDEBUG("QueueItemEstablish::QueueItemEstablish (" << item << ")");
00077 
00078 }
00079 
00080 
00081 QueueItemEstablish::~QueueItemEstablish()
00082 {
00083 }
00084 
00085 //---------------------------------------------------------------------------
00086 
00087 bool
00088 QueueItemEstablish::isSatisfied (ResolverContext_Ptr context) const
00089 {
00090     return context->isPresent (_item);
00091 }
00092 
00093 
00094 //---------------------------------------------------------------------------
00095 
00096 
00097 bool
00098 QueueItemEstablish::process (ResolverContext_Ptr context, QueueItemList & qil)
00099 {
00100     _XDEBUG("QueueItemEstablish::process(" << *this << ")");
00101 
00102     ResStatus status = context->getStatus(_item);
00103     
00104     if (_item.status().isLocked()
00105         || status.isLocked()) {
00106         _XDEBUG("Item " << _item << " is locked. --> NO establish");
00107         return true;
00108     }
00109     if ( ! _item->arch().compatibleWith( context->architecture() ) ) {
00110         context->unneeded (_item, _other_penalty);
00111         _DEBUG( _item << " has incompatible architecture, unneeded" );
00112         return true;
00113     }
00114 
00115     _item.status().setUndetermined();           // reset any previous establish state
00116 
00117     CapSet freshens = _item->dep(Dep::FRESHENS);
00118 
00119     _XDEBUG("simple establish of " << _item << " with " << freshens.size() << " freshens");
00120 
00121     ResolverInfo_Ptr misc_info = new ResolverInfoMisc (RESOLVER_INFO_TYPE_ESTABLISHING, _item, RESOLVER_INFO_PRIORITY_VERBOSE);
00122     context->addInfo (misc_info);
00123     logInfo (context);
00124 
00125     /* Loop through all freshen dependencies. If one is satisfied, queue the _item for installation.  */
00126 
00127     CapSet::const_iterator iter;
00128     for (iter = freshens.begin(); iter != freshens.end(); iter++) {
00129         const Capability cap = *iter;
00130         if (context->requirementIsMet (cap)) {
00131             _XDEBUG("this freshens " << cap);
00132             break;
00133         }
00134     }
00135 
00136     // if we have freshens but none of the freshen deps were met, mark the _item as unneeded
00137     // else we look at its requires to set it to satisfied or incomplete
00138 
00139     if (status.staysUninstalled()
00140         && freshens.size() > 0                          // have freshens !
00141         && iter == freshens.end())
00142     {
00143         _DEBUG(_item << " freshens nothing -> unneeded");
00144         if (_item->kind() != ResTraits<Package>::kind)
00145             context->unneeded (_item, _other_penalty);
00146     }
00147     else {                                                      // installed or no freshens or triggered freshens
00148 
00149         CapSet supplements = _item->dep(Dep::SUPPLEMENTS);
00150         if (supplements.size() != 0) {                                  // if we have supplements, they must _also_ trigger
00151             CapSet::const_iterator iter;
00152             for (iter = supplements.begin(); iter != supplements.end(); iter++) {
00153                 const Capability cap = *iter;
00154                 if (context->requirementIsMet (cap)) {
00155                     _XDEBUG("this supplements " << cap);
00156                     break;
00157                 }
00158             }
00159             if (iter == supplements.end()) {
00160                 _DEBUG(_item << " none of the supplements match -> unneeded");
00161                 if (_item->kind() != ResTraits<Package>::kind)
00162                     context->unneeded (_item, _other_penalty);
00163                 return true;
00164             }
00165 
00166             PoolItem_Ref installed = Helper::findInstalledItem( pool(), _item );
00167             if (!installed) {                                                           // not installed -> install
00168                 // have supplements and at least one triggers -> install
00169                 QueueItemInstall_Ptr install_item = new QueueItemInstall( pool(), _item, true );
00170                 qil.push_front( install_item );
00171                 return true;
00172             }
00173         }
00174 
00175 
00176         CapSet requires = _item->dep(Dep::REQUIRES);                    // check requirements
00177         Capability missing;
00178         for (iter = requires.begin(); iter != requires.end(); iter++) {
00179             missing = *iter;
00180             if (!context->requirementIsMet (missing)) {
00181                 break;
00182             }
00183         }
00184         if (iter == requires.end()) {                                   // all are met
00185 #if 0   // now disabled
00186 
00187 // why do we install when requirements are met ?
00188 // this code should probably be removed completely.
00189 // if all requirements are met, the item is satisfied
00190 //  there is no reason to install it.
00191 
00192             if (_item->kind() == ResTraits<Package>::kind
00193                 || _item->kind() == ResTraits<Pattern>::kind
00194                 || _item->kind() == ResTraits<Selection>::kind)
00195             {
00196                 if (status.staysUninstalled())
00197                 {
00198                     _DEBUG("Uninstalled " << _item << " has all requirements -> install");
00199                     QueueItemInstall_Ptr install_item = new QueueItemInstall( pool(), _item );
00200                     qil.push_front( install_item );
00201                 }
00202             }
00203             else {
00204 #endif
00205                 _DEBUG("all requirements of " << _item << " met -> satisfied");
00206                 context->satisfy (_item, _other_penalty);
00207 #if 0
00208             }
00209 #endif
00210         }
00211         else {
00212             // If the item stays installed, blame the user
00213             if ((_item->kind() != ResTraits<Package>::kind
00214                  && _item->kind() != ResTraits<Atom>::kind)
00215                 || status.staysInstalled()
00216                 || context->establishing())
00217             {
00218                 _DEBUG("Non-Package/Installed/Establishing " << _item << " has unfulfilled requirement " << *iter << " -> incomplete");
00219                 context->incomplete( _item, _other_penalty );
00220             }
00221             else if (status.staysUninstalled())                 // not installed -> schedule for installation
00222             {
00223                 _DEBUG("Uninstalled " << _item << " has unfulfilled requirement " << *iter << " -> install");
00224                 QueueItemInstall_Ptr install_item = new QueueItemInstall( pool(), _item );
00225                 qil.push_front( install_item );
00226             }
00227             else {
00228                 _DEBUG("Transacted " << _item << " has unfulfilled requirement " << *iter << " -> leave");
00229                 // do nothing, because its either toBeInstalled or toBeUninstalled
00230             }
00231         }
00232     }
00233 
00234     return true;
00235 }
00236 
00237 
00238 QueueItem_Ptr
00239 QueueItemEstablish::copy (void) const
00240 {
00241     QueueItemEstablish_Ptr new_install = new QueueItemEstablish (pool(), _item, _soft);
00242     new_install->QueueItem::copy(this);
00243 
00244     new_install->_channel_priority = _channel_priority;
00245     new_install->_other_penalty = _other_penalty;
00246     new_install->_explicitly_requested = _explicitly_requested;
00247 
00248     return new_install;
00249 }
00250 
00251 
00252 int
00253 QueueItemEstablish::cmp (QueueItem_constPtr item) const
00254 {
00255     int cmp = this->compare (item);
00256     if (cmp != 0)
00257         return cmp;
00258     QueueItemEstablish_constPtr establish = dynamic_pointer_cast<const QueueItemEstablish>(item);
00259     return compareByNVR(_item.resolvable(), establish->_item.resolvable());
00260 }
00261 
00263     };// namespace detail
00266   };// namespace solver
00269 };// namespace zypp

Generated on Thu May 4 16:03:25 2006 for zypp by  doxygen 1.4.6