SolutionAction.cc

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /* SolutionAction.cc
00003  *
00004  * Easy-to use interface to the ZYPP dependency resolver
00005  *
00006  * Copyright (C) 2000-2002 Ximian, Inc.
00007  * Copyright (C) 2005 SUSE Linux Products GmbH
00008  *
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU General Public License,
00011  * version 2, as published by the Free Software Foundation.
00012  *
00013  * This program is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program; if not, write to the Free Software
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00021  * 02111-1307, USA.
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         case ALLBRANCHES_ON:    os << "All branches on"; break;
00071         case ALLBRANCHES_OFF:   os << "All branches off"; break;            
00072         case DOUBLETIMEOUT:     os << "Double timeout"; break;
00073     }
00074     os << " ";
00075     os << _item;
00076     os << endl;
00077     return os;
00078 }
00079 
00080 
00081 ostream&
00082 operator<<( ostream& os, const SolutionActionList & actionlist)
00083 {
00084     for (SolutionActionList::const_iterator iter = actionlist.begin(); iter != actionlist.end(); ++iter) {
00085         os << *(*iter);
00086         os << endl;
00087     }
00088     return os;
00089 }
00090 
00091 
00092 ostream&
00093 operator<<( ostream& os, const CSolutionActionList & actionlist)
00094 {
00095     for (CSolutionActionList::const_iterator iter = actionlist.begin(); iter != actionlist.end(); ++iter) {
00096         os << *(*iter);
00097         os << endl;
00098     }
00099     return os;
00100 }
00101 
00102 //---------------------------------------------------------------------------
00103 
00104 ostream &
00105 InjectSolutionAction::dumpOn( ostream& os ) const
00106 {
00107     os << "InjectSolutionAction: ";
00108     os << _capability;
00109     os << ", ";
00110     switch (_kind) {
00111         case REQUIRES:  os << "Requires"; break;
00112         case CONFLICTS: os << "Conflicts"; break;
00113         case OBSOLETES: os << "Obsoletes"; break;
00114         case INSTALLED: os << "Installed"; break;
00115         case ARCHITECTURE: os << "Architecture"; break;
00116         case VENDOR: os << "Vendor"; break;                 
00117         default: os << "Wrong kind"; break;
00118     }
00119     os << " ";
00120     os << _item;            
00121     os << endl;
00122     return os;
00123 }
00124 
00125 //---------------------------------------------------------------------------
00126 
00127 
00128 ostream &
00129 SolutionAction::dumpOn( std::ostream & os ) const
00130 {
00131     os << "SolutionAction<";
00132     os << "not specified";
00133     os << "> ";
00134     return os;
00135 }
00136 
00137 
00138 bool 
00139 TransactionSolutionAction::execute(Resolver & resolver) const
00140 {
00141     bool ret = true;
00142     switch (action()) {
00143         case KEEP:
00144             resolver.addIgnoreInstalledItem( _item );
00145             /*FALLTHRU*/
00146         case INSTALL:
00147             if (_item.status().isToBeUninstalled())
00148                 ret = _item.status().setTransact (false, ResStatus::USER);
00149             else
00150                 _item.status().setToBeInstalled (ResStatus::USER);
00151             break;
00152         case REMOVE:
00153             if (_item.status().isToBeInstalled()) {
00154                 _item.status().setTransact (false,ResStatus::USER);
00155                 _item.status().setLock (true,ResStatus::USER); // no other dependency can set it again          
00156             } else if (_item.status().isInstalled())
00157                 _item.status().setToBeUninstalled (ResStatus::USER);
00158             else
00159                 _item.status().setLock (true,ResStatus::USER); // no other dependency can set it again          
00160             break;
00161         case UNLOCK:
00162             ret = _item.status().setLock (false, ResStatus::USER);
00163             if (!ret) ERR << "Cannot unlock " << _item << endl;
00164             break;
00165         case ALLBRANCHES_ON:
00166             resolver.setTryAllPossibilities (true);
00167             break;
00168         case ALLBRANCHES_OFF:
00169             resolver.setTryAllPossibilities (false);
00170             break;
00171         case DOUBLETIMEOUT:
00172             resolver.setTimeout (resolver.timeout()*2);
00173             break;          
00174         default:
00175             ERR << "Wrong TransactionKind" << endl;
00176             ret = false;
00177     }
00178     return ret;
00179 }
00180 
00181 bool
00182 InjectSolutionAction::execute(Resolver & resolver) const
00183 {
00184     Dependencies dependencies;
00185     CapSet depList;
00186     if (_item != PoolItem_Ref()) {    
00187         dependencies = _item.resolvable()->deps();
00188         depList = dependencies[Dep::CONFLICTS];
00189     }
00190     switch (_kind) {
00191         case CONFLICTS:
00192             // removing conflict in both resolvables
00193             for (CapSet::const_iterator iter = depList.begin(); iter != depList.end(); iter++) {
00194                 if (iter->matches (_capability) == CapMatch::yes )
00195                 {
00196                     resolver.addIgnoreConflict (_item, _capability);
00197                 }
00198             }
00199             // Obsoletes are conflicts too
00200             depList = dependencies[Dep::OBSOLETES];
00201             for (CapSet::const_iterator iter = depList.begin(); iter != depList.end(); iter++) {
00202                 if (iter->matches (_capability) == CapMatch::yes )
00203                 {
00204                     resolver.addIgnoreConflict (_otherItem, _capability);
00205                 }
00206             }
00207             
00208             dependencies = _otherItem.resolvable()->deps();
00209             depList = dependencies[Dep::CONFLICTS];
00210             for (CapSet::const_iterator iter = depList.begin(); iter != depList.end(); iter++) {
00211                 if (iter->matches (_capability) == CapMatch::yes )
00212                 {
00213                     resolver.addIgnoreConflict (_otherItem, _capability);
00214                 }
00215             }
00216             // Obsoletes are conflicts too          
00217             depList = dependencies[Dep::OBSOLETES];
00218             for (CapSet::const_iterator iter = depList.begin(); iter != depList.end(); iter++) {
00219                 if (iter->matches (_capability) == CapMatch::yes )
00220                 {
00221                     resolver.addIgnoreConflict (_otherItem, _capability);
00222                 }
00223             }
00224             
00225             break;
00226         case REQUIRES:
00227             // removing the requires dependency from the item
00228             if (_item == PoolItem_Ref()) {
00229                 // this was a requirement via Resolver::addExtraCapability
00230                 // so we have to delete it.
00231                 resolver.removeExtraCapability (_capability);
00232             } else {
00233                 resolver.addIgnoreRequires (_item, _capability);
00234             }
00235             break;
00236         case ARCHITECTURE:
00237             // This item is for ALL architectures available
00238             resolver.addIgnoreArchitectureItem (_item);
00239             break;
00240         case VENDOR:
00241             // This item is for ALL vendor available
00242             resolver.addIgnoreVendorItem (_item);
00243             break;                  
00244         case OBSOLETES:
00245             // removing the obsoletes dependency from the item
00246             resolver.addIgnoreObsoletes (_otherItem, _capability);
00247             break;          
00248         case INSTALLED:
00249             // ignoring already installed items
00250             resolver.addIgnoreInstalledItem (_item);
00251             resolver.addIgnoreInstalledItem (_otherItem);
00252             break;
00253         default:
00254             ERR << "No valid InjectSolutionAction kind found" << endl;
00255             return false;
00256     }
00257 
00258     return true;
00259 }
00260 
00262     };// namespace detail
00265   };// namespace solver
00268 };// namespace zypp

Generated on Tue Sep 25 19:23:08 2007 for libzypp by  doxygen 1.5.3