From: Michael Andres Date: Mon, 22 May 2006 15:20:32 +0000 (+0000) Subject: - Order all objects according to prerequirements, not just packages. X-Git-Tag: BASE-SuSE-SLE-10-SP2-Branch~770 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=98296d591d86ba378b88dca5da011735fd57815d;p=platform%2Fupstream%2Flibzypp.git - Order all objects according to prerequirements, not just packages. (#173690) --- diff --git a/devel/devel.ma/Parse.cc b/devel/devel.ma/Parse.cc index 5311348..42cbd47 100644 --- a/devel/devel.ma/Parse.cc +++ b/devel/devel.ma/Parse.cc @@ -18,6 +18,7 @@ #include "zypp/Package.h" #include "zypp/Language.h" #include "zypp/NameKindProxy.h" +#include "zypp/pool/GetResolvablesToInsDel.h" using namespace std; @@ -81,11 +82,7 @@ template struct PrintPoolItem { void operator()( const PoolItem & pi ) const - { - USR << "S" << pi->source().numericId() - << "/M" << pi->sourceMediaNr() - << " " << pi << endl; - } + { USR << pi << " (" << pi.resolvable().get() << ")" < @@ -160,65 +157,6 @@ inline bool selectForTransact( const NameKindProxy & nkp ) /////////////////////////////////////////////////////////////////// -namespace zypp -{ - namespace pool - { - struct CollectTransacting - { - CollectTransacting( const ResPool & pool ) - { - dumpPoolStats( SEC, - make_filter_begin(pool), - make_filter_end(pool) ); - } - - typedef std::list PoolItemList; - PoolItemSet _toInstall; - PoolItemSet _toDelete; - PoolItemSet _skipToDelete; - }; -#if 0 - struct CollectTransacting - { - typedef std::list PoolItemList; - - void operator()( const PoolItem & pi ) - { - if ( pi.status().isToBeInstalled() ) - { - _toInstall.insert( pi ); - } - else if ( pi.status().isToBeUninstalled() ) - { - if ( pi.status().isToBeUninstalledDueToObsolete() - || pi.status().isToBeUninstalledDueToUpgrade() ) - _skipToDelete.insert( pi ); - else - _toDelete.insert( pi ); - } - } - - PoolItemSet _toInstall; - PoolItemSet _toDelete; - PoolItemSet _skipToDelete; - }; -#endif - - std::ostream & operator<<( std::ostream & str, const CollectTransacting & obj ) - { - str << "CollectTransacting:" << endl; - dumpPoolStats( str << " toInstall: ", - obj._toInstall.begin(), obj._toInstall.end() ) << endl; - dumpPoolStats( str << " toDelete: ", - obj._toDelete.begin(), obj._toDelete.end() ) << endl; - dumpPoolStats( str << " skipToDelete: ", - obj._skipToDelete.begin(), obj._skipToDelete.end() ) << endl; - return str; - } - } -} - /****************************************************************** ** ** FUNCTION NAME : main @@ -233,17 +171,19 @@ int main( int argc, char * argv[] ) if ( 1 ) { + zypp::base::LogControl::TmpLineWriter shutUp; getZYpp()->initTarget( sysRoot ); - getZYpp()->addResolvables( getZYpp()->target()->resolvables(), true ); + //getZYpp()->addResolvables( getZYpp()->target()->resolvables(), true ); USR << "Added target: " << pool << endl; } if ( 1 ) { + zypp::base::LogControl::TmpLineWriter shutUp; SourceManager::sourceManager()->restore( sysRoot ); if ( SourceManager::sourceManager()->allSources().empty() ) { - Source_Ref src1( createSource( "dir:/mounts/machcd2/CDs/SLES-10-CD-i386-Beta10/CD1" ) ); - Source_Ref src2( createSource( "dir:/mounts/machcd2/kukuk/sles10-sp-i386/CD1" ) ); + Source_Ref src1( createSource( "dir:///Local/SUSE-Linux-10.1-Build_830-i386/CD1" ) ); + Source_Ref src2( createSource( "dir:///Local/SUSE-Linux-10.1-Build_830-Addon-BiArch/CD1" ) ); SourceManager::sourceManager()->addSource( src1 ); SourceManager::sourceManager()->addSource( src2 ); SourceManager::sourceManager()->store( sysRoot, true ); @@ -255,7 +195,8 @@ int main( int argc, char * argv[] ) ) << endl; } - USR << pool << endl; + MIL << *SourceManager::sourceManager() << endl; + MIL << pool << endl; //dumpRange( USR << "Pool: " << pool, // pool.begin(), pool.end() // ) << endl; @@ -275,24 +216,33 @@ int main( int argc, char * argv[] ) selectForTransact( nameKindProxy( pool, "Office" ) ); } + //getZYpp()->commit( ZYppCommitPolicy() ), + vdumpPoolStats( USR << "Transacting:"<< endl, make_filter_begin(pool), make_filter_end(pool) ) << endl; - bool eres, rres; { zypp::base::LogControl::TmpLineWriter shutUp; + zypp::base::LogControl::instance().logfile( "SOLVER" ); eres = getZYpp()->resolver()->establishPool(); rres = getZYpp()->resolver()->resolvePool(); } MIL << "est " << eres << " slv " << rres << endl; - vdumpPoolStats( USR << "Transacting:"<< endl, + dumpPoolStats( USR << "Transacting:"<< endl, make_filter_begin(pool), make_filter_end(pool) ) << endl; + pool::GetResolvablesToInsDel collect( pool ); + MIL << "GetResolvablesToInsDel:" << endl << collect << endl; + + dumpRange( WAR << "toInstall: " << endl, + collect._toInstall.begin(), collect._toInstall.end() ) << endl; + dumpRange( ERR << "toDelete: " << endl, + collect._toDelete.begin(), collect._toDelete.end() ) << endl; INT << "===[END]============================================" << endl << endl; diff --git a/package/libzypp.changes b/package/libzypp.changes index cccd6db..c5bb006 100644 --- a/package/libzypp.changes +++ b/package/libzypp.changes @@ -1,13 +1,19 @@ ------------------------------------------------------------------- +Mon May 22 17:19:25 CEST 2006 - ma@suse.de + +- Order all objects according to prerequirements, not just packages. + (#173690) + +------------------------------------------------------------------- Mon May 22 15:57:43 CEST 2006 - schubi@suse.de -- Added new translation +- Added new translation ------------------------------------------------------------------- Fri May 19 12:53:44 CEST 2006 - dmacvicar@suse.de - fix missing homedir option for gpg (#171055) -- rev 3415 +- rev 3415 ------------------------------------------------------------------- Thu May 18 19:08:52 CEST 2006 - ma@suse.de diff --git a/zypp/Resolvable.cc b/zypp/Resolvable.cc index 705d885..e6dcee6 100644 --- a/zypp/Resolvable.cc +++ b/zypp/Resolvable.cc @@ -14,6 +14,9 @@ #include "zypp/Resolvable.h" #include "zypp/detail/ResolvableImpl.h" +#include "zypp/ResObject.h" +#include "zypp/Source.h" + using namespace std; /////////////////////////////////////////////////////////////////// @@ -45,7 +48,14 @@ namespace zypp /////////////////////////////////////////////////////////////////// std::ostream & Resolvable::dumpOn( std::ostream & str ) const - { return _pimpl->dumpOn( str ); } + { + const ResObject * obj = dynamic_cast(this); + if ( obj ) + { + str << "[S" << obj->source().numericId() << ":" << obj->sourceMediaNr() << "]"; + } + return _pimpl->dumpOn( str ); + } const Resolvable::Kind & Resolvable::kind() const { return _pimpl->kind(); } diff --git a/zypp/pool/GetResolvablesToInsDel.cc b/zypp/pool/GetResolvablesToInsDel.cc new file mode 100644 index 0000000..0f9c9fa --- /dev/null +++ b/zypp/pool/GetResolvablesToInsDel.cc @@ -0,0 +1,352 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/pool/GetResolvablesToInsDel.cc + * +*/ +#include +#include + +#include "zypp/base/Logger.h" + +#include "zypp/pool/GetResolvablesToInsDel.h" +#include "zypp/pool/PoolStats.h" + +#include "zypp/solver/detail/InstallOrder.h" + +using std::endl; +using zypp::solver::detail::InstallOrder; + +#undef ZYPP_BASE_LOGGER_LOGGROUP +#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::GetResolvablesToInsDel" + + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace pool + { ///////////////////////////////////////////////////////////////// + + /****************************************************************** + ** + ** FUNCTION NAME : strip_obsoleted_to_delete + ** FUNCTION TYPE : void + ** + ** strip packages to_delete which get obsoleted by + ** to_install (i.e. delay deletion in case the + ** obsoleting package likes to save whatever... + */ + + static void + strip_obsoleted_to_delete( GetResolvablesToInsDel::PoolItemList & deleteList_r, + const GetResolvablesToInsDel::PoolItemList & instlist_r ) + { + if ( deleteList_r.size() == 0 || instlist_r.size() == 0 ) + return; // ---> nothing to do + + // build obsoletes from instlist_r + CapSet obsoletes; + for ( GetResolvablesToInsDel::PoolItemList::const_iterator it = instlist_r.begin(); + it != instlist_r.end(); ++it ) + { + PoolItem_Ref item( *it ); + obsoletes.insert( item->dep(Dep::OBSOLETES).begin(), item->dep(Dep::OBSOLETES).end() ); + } + if ( obsoletes.size() == 0 ) + return; // ---> nothing to do + + // match them... ;( + GetResolvablesToInsDel::PoolItemList undelayed; + // forall applDelete Packages... + for ( GetResolvablesToInsDel::PoolItemList::iterator it = deleteList_r.begin(); + it != deleteList_r.end(); ++it ) + { + PoolItem_Ref ipkg( *it ); + bool delayPkg = false; + // ...check whether an obsoletes.... + for ( CapSet::iterator obs = obsoletes.begin(); + ! delayPkg && obs != obsoletes.end(); ++obs ) + { + // ...matches anything provided by the package? + for ( CapSet::const_iterator prov = ipkg->dep(Dep::PROVIDES).begin(); + prov != ipkg->dep(Dep::PROVIDES).end(); ++prov ) + { + if ( obs->matches( *prov ) == CapMatch::yes ) + { + // if so, delay package deletion + DBG << "Ignore appl_delete (should be obsoleted): " << ipkg << endl; + delayPkg = true; + ipkg.status().resetTransact( ResStatus::USER ); + break; + } + } + } + if ( ! delayPkg ) { + DBG << "undelayed " << ipkg << endl; + undelayed.push_back( ipkg ); + } + } + // Puhh... + deleteList_r.swap( undelayed ); + } + + /////////////////////////////////////////////////////////////////// + // + // METHOD NAME : GetResolvablesToInsDel::GetResolvablesToInsDel + // METHOD TYPE : Ctor + // + GetResolvablesToInsDel::GetResolvablesToInsDel( ResPool pool_r ) + { + typedef std::set PoolItemSet; + + PoolItemList & dellist_r( _toDelete ); + PoolItemList & instlist_r( _toInstall ); + PoolItemList & srclist_r( _toSrcinstall ); + + for ( ResPool::const_iterator it = pool_r.begin(); it != pool_r.end(); ++it ) + { + if (it->status().isToBeInstalled()) + { + if ((*it)->kind() == ResTraits::kind) { + srclist_r.push_back( *it ); + } + else + instlist_r.push_back( *it ); + } + else if (it->status().isToBeUninstalled()) + { + if ( it->status().isToBeUninstalledDueToObsolete() ) + { + DBG << "Ignore auto_delete (should be obsoleted): " << *it << endl; + } + else if ( it->status().isToBeUninstalledDueToUpgrade() ) + { + DBG << "Ignore auto_delete (should be upgraded): " << *it << endl; + } + else { + dellist_r.push_back( *it ); + } + } + } + + MIL << "ResolvablesToInsDel: delete " << dellist_r.size() + << ", install " << instlist_r.size() + << ", srcinstall " << srclist_r.size() << endl; + + /////////////////////////////////////////////////////////////////// + // + // strip packages to_delete which get obsoleted by + // to_install (i.e. delay deletion in case the + // obsoleting package likes to save whatever... + // + /////////////////////////////////////////////////////////////////// + strip_obsoleted_to_delete( dellist_r, instlist_r ); + + if ( dellist_r.size() ) { + /////////////////////////////////////////////////////////////////// + // + // sort delete list... + // + /////////////////////////////////////////////////////////////////// + PoolItemSet delset( dellist_r.begin(), dellist_r.end() ); // for delete order + PoolItemSet dummy; // dummy, empty, should contain already installed + + InstallOrder order( pool_r, delset, dummy ); // sort according top prereq + order.init(); + const PoolItemList dsorted( order.getTopSorted() ); + + dellist_r.clear(); + for ( PoolItemList::const_reverse_iterator cit = dsorted.rbegin(); + cit != dsorted.rend(); ++cit ) + { + dellist_r.push_back( *cit ); + } + } + + /////////////////////////////////////////////////////////////////// + // + // sort installed list... + // + /////////////////////////////////////////////////////////////////// + if ( instlist_r.empty() ) + return; + +#warning Source Rank Priority ? +#if 0 + /////////////////////////////////////////////////////////////////// + // Get desired order of InstSrc'es to install from. + /////////////////////////////////////////////////////////////////// + typedef map RankPriority; + + RankPriority rankPriority; + { + InstSrcManager::ISrcIdList sourcerank( Y2PM::instSrcManager().instOrderSources() ); + // map InstSrc rank to install priority + unsigned prio = 0; + for ( InstSrcManager::ISrcIdList::const_iterator it = sourcerank.begin(); + it != sourcerank.end(); ++it, ++prio ) { + rankPriority[(*it)->descr()->default_rank()] = prio; + } + } +#endif + + /////////////////////////////////////////////////////////////////// + // Compute install order according to packages prereq. + // Try to group packages with respect to the desired install order + /////////////////////////////////////////////////////////////////// + // backup list for debug purpose. + // You can as well build the set, clear the list and rebuild it in install order. + PoolItemList instbackup_r; + instbackup_r.swap( instlist_r ); + + PoolItemSet insset( instbackup_r.begin(), instbackup_r.end() ); // for install order + PoolItemSet installed; // dummy, empty, should contain already installed + + InstallOrder order( pool_r, insset, installed ); + // start recursive depth-first-search + order.init(); + MIL << "order.init() done" << endl; + order.printAdj( XXX, false ); + /////////////////////////////////////////////////////////////////// + // build install list in install order + /////////////////////////////////////////////////////////////////// + PoolItemList best_list; + unsigned best_prio = 0; + unsigned best_medianum = 0; + + PoolItemList last_list; + unsigned last_prio = 0; + unsigned last_medianum = 0; + + PoolItemList other_list; + + for ( PoolItemList items = order.computeNextSet(); ! items.empty(); items = order.computeNextSet() ) + { + MIL << "order.computeNextSet: " << items.size() << " resolvables" << endl; + /////////////////////////////////////////////////////////////////// + // items contains all objects we could install now. Pick all objects + // from current media, or best media if none for current. Alwayys pick + // objects that do not require media access. + /////////////////////////////////////////////////////////////////// + + best_list.clear(); + last_list.clear(); + other_list.clear(); + + for ( PoolItemList::iterator cit = items.begin(); cit != items.end(); ++cit ) + { + ResObject::constPtr cobj( cit->resolvable() ); + if (!cobj) + continue; + + if ( ! cobj->sourceMediaNr() ) { + XXX << "No media access required for " << *cit << endl; + order.setInstalled( *cit ); + other_list.push_back( *cit ); + continue; + } + + XXX << "Package " << *cobj << ", media " << cobj->sourceMediaNr() << " last_medianum " << last_medianum << " best_medianum " << best_medianum << endl; + if ( cobj->source().numericId() == last_prio && + cobj->sourceMediaNr() == last_medianum ) { + // prefer packages on current media. + last_list.push_back( *cit ); + continue; + } + + if ( last_list.empty() ) { + // check for best media as long as there are no packages for current media. + + if ( ! best_list.empty() ) { + + if ( cobj->source().numericId() < best_prio ) { + best_list.clear(); // new best + } else if ( cobj->source().numericId() == best_prio ) { + if ( cobj->sourceMediaNr() < best_medianum ) { + best_list.clear(); // new best + } else if ( cobj->sourceMediaNr() == best_medianum ) { + best_list.push_back( *cit ); // same as best -> add + continue; + } else { + continue; // worse + } + } else { + continue; // worse + } + } + + if ( best_list.empty() ) + { + // first package or new best + best_list.push_back( *cit ); + best_prio = cobj->source().numericId(); + best_medianum = cobj->sourceMediaNr(); + continue; + } + } + + } // for all objects in current set + + /////////////////////////////////////////////////////////////////// + // remove objects picked from install order and append them to + // install list. + /////////////////////////////////////////////////////////////////// + PoolItemList & take_list( last_list.empty() ? best_list : last_list ); + if ( last_list.empty() ) + { + MIL << "SET NEW media " << best_medianum << endl; + last_prio = best_prio; + last_medianum = best_medianum; + } + else + { + MIL << "SET CONTINUE" << endl; + } + + for ( PoolItemList::iterator it = take_list.begin(); it != take_list.end(); ++it ) + { + order.setInstalled( *it ); + XXX << "SET isrc " << (*it)->source().numericId() << " -> " << (*it) << endl; + } + // move everthing from take_list to the end of instlist_r, clean take_list + instlist_r.splice( instlist_r.end(), take_list ); + // same for other_list + instlist_r.splice( instlist_r.end(), other_list ); + + } // for all sets computed + + + if ( instbackup_r.size() != instlist_r.size() ) + { + ERR << "***************** Lost packages in InstallOrder sort." << endl; + } + + } + + /****************************************************************** + ** + ** FUNCTION NAME : operator<< + ** FUNCTION TYPE : std::ostream & + */ + std::ostream & operator<<( std::ostream & str, const GetResolvablesToInsDel & obj ) + { + dumpPoolStats( str << "toInstall: " << endl, + obj._toInstall.begin(), obj._toInstall.end() ) << endl; + dumpPoolStats( str << "toDelete: " << endl, + obj._toDelete.begin(), obj._toDelete.end() ) << endl; + return str; + } + + ///////////////////////////////////////////////////////////////// + } // namespace pool + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// + diff --git a/zypp/pool/GetResolvablesToInsDel.h b/zypp/pool/GetResolvablesToInsDel.h new file mode 100644 index 0000000..ee432b4 --- /dev/null +++ b/zypp/pool/GetResolvablesToInsDel.h @@ -0,0 +1,56 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/pool/GetResolvablesToInsDel.h + * +*/ +#ifndef ZYPP_POOL_GETRESOLVABLESTOINSDEL_H +#define ZYPP_POOL_GETRESOLVABLESTOINSDEL_H + +#include +#include + +#include "zypp/ResPool.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////// + namespace pool + { ///////////////////////////////////////////////////////////////// + + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : GetResolvablesToInsDel + // + /** Collect transacting items and sort according to prereqs and + * media access. + */ + struct GetResolvablesToInsDel + { + typedef std::list PoolItemList; + + /** */ + GetResolvablesToInsDel( ResPool pool_r ); + + PoolItemList _toDelete; + PoolItemList _toInstall; + PoolItemList _toSrcinstall; + }; + /////////////////////////////////////////////////////////////////// + + /** \relates GetResolvablesToInsDel Stream output */ + std::ostream & operator<<( std::ostream & str, const GetResolvablesToInsDel & obj ); + + ///////////////////////////////////////////////////////////////// + } // namespace pool + /////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// +#endif // ZYPP_POOL_GETRESOLVABLESTOINSDEL_H diff --git a/zypp/pool/Makefile.am b/zypp/pool/Makefile.am index 3c5d443..669c027 100644 --- a/zypp/pool/Makefile.am +++ b/zypp/pool/Makefile.am @@ -14,7 +14,8 @@ baseinclude_HEADERS = \ PoolTraits.h \ PoolImpl.h \ \ - PoolStats.h + PoolStats.h \ + GetResolvablesToInsDel.h noinst_LTLIBRARIES = lib@PACKAGE@_pool.la @@ -23,7 +24,8 @@ noinst_LTLIBRARIES = lib@PACKAGE@_pool.la lib@PACKAGE@_pool_la_SOURCES = \ PoolImpl.cc \ \ - PoolStats.cc + PoolStats.cc \ + GetResolvablesToInsDel.cc # lib@PACKAGE@_pool_la_LIBADD = diff --git a/zypp/target/TargetImpl.cc b/zypp/target/TargetImpl.cc index b606e63..08265fb 100644 --- a/zypp/target/TargetImpl.cc +++ b/zypp/target/TargetImpl.cc @@ -32,12 +32,12 @@ #include "zypp/target/TargetImpl.h" #include "zypp/target/TargetCallbackReceiver.h" +#include "zypp/pool/GetResolvablesToInsDel.h" #include "zypp/solver/detail/Helper.h" -#include "zypp/solver/detail/InstallOrder.h" using namespace std; using zypp::solver::detail::Helper; -using zypp::solver::detail::InstallOrder; +//using zypp::solver::detail::InstallOrder; /////////////////////////////////////////////////////////////////// namespace zypp @@ -512,308 +512,18 @@ namespace zypp return rpm::RpmDb::setInstallationLogfile(path_r); } -//----------------------------------------------------------------------------- -/****************************************************************** -** -** -** FUNCTION NAME : strip_obsoleted_to_delete -** FUNCTION TYPE : void -** -** strip packages to_delete which get obsoleted by -** to_install (i.e. delay deletion in case the -** obsoleting package likes to save whatever... -*/ - -static void -strip_obsoleted_to_delete( TargetImpl::PoolItemList & deleteList_r, - const TargetImpl::PoolItemList & instlist_r ) -{ - if ( deleteList_r.size() == 0 || instlist_r.size() == 0 ) - return; // ---> nothing to do - - // build obsoletes from instlist_r - CapSet obsoletes; - for ( TargetImpl::PoolItemList::const_iterator it = instlist_r.begin(); - it != instlist_r.end(); ++it ) - { - PoolItem_Ref item( *it ); - obsoletes.insert( item->dep(Dep::OBSOLETES).begin(), item->dep(Dep::OBSOLETES).end() ); - } - if ( obsoletes.size() == 0 ) - return; // ---> nothing to do - - // match them... ;( - TargetImpl::PoolItemList undelayed; - // forall applDelete Packages... - for ( TargetImpl::PoolItemList::iterator it = deleteList_r.begin(); - it != deleteList_r.end(); ++it ) - { - PoolItem_Ref ipkg( *it ); - bool delayPkg = false; - // ...check whether an obsoletes.... - for ( CapSet::iterator obs = obsoletes.begin(); - ! delayPkg && obs != obsoletes.end(); ++obs ) + void + TargetImpl::getResolvablesToInsDel ( const ResPool pool_r, + TargetImpl::PoolItemList & dellist_r, + TargetImpl::PoolItemList & instlist_r, + TargetImpl::PoolItemList & srclist_r ) const { - // ...matches anything provided by the package? - for ( CapSet::const_iterator prov = ipkg->dep(Dep::PROVIDES).begin(); - prov != ipkg->dep(Dep::PROVIDES).end(); ++prov ) - { - if ( obs->matches( *prov ) == CapMatch::yes ) - { - // if so, delay package deletion - DBG << "Ignore appl_delete (should be obsoleted): " << ipkg << endl; - delayPkg = true; - ipkg.status().resetTransact( ResStatus::USER ); - break; - } - } - } - if ( ! delayPkg ) { - DBG << "undelayed " << ipkg << endl; - undelayed.push_back( ipkg ); + pool::GetResolvablesToInsDel collect( pool_r ); + MIL << "GetResolvablesToInsDel: " << endl << collect << endl; + dellist_r.swap( collect._toDelete ); + instlist_r.swap( collect._toInstall ); + srclist_r.swap( collect._toSrcinstall ); } - } - // Puhh... - deleteList_r.swap( undelayed ); -} - - - - -void -TargetImpl::getResolvablesToInsDel ( const ResPool pool_r, - TargetImpl::PoolItemList & dellist_r, - TargetImpl::PoolItemList & instlist_r, - TargetImpl::PoolItemList & srclist_r ) const -{ - dellist_r.clear(); - instlist_r.clear(); - srclist_r.clear(); - TargetImpl::PoolItemList nonpkglist; - - for ( ResPool::const_iterator it = pool_r.begin(); it != pool_r.end(); ++it ) - { - if (it->status().isToBeInstalled()) - { - if ((*it)->kind() == ResTraits::kind) { - srclist_r.push_back( *it ); - } - else if ((*it)->kind() != ResTraits::kind) { - nonpkglist.push_back( *it ); - } - else - instlist_r.push_back( *it ); - } - else if (it->status().isToBeUninstalled()) - { - if ( it->status().isToBeUninstalledDueToObsolete() ) - { - DBG << "Ignore auto_delete (should be obsoleted): " << *it << endl; - } - else if ( it->status().isToBeUninstalledDueToUpgrade() ) - { - DBG << "Ignore auto_delete (should be upgraded): " << *it << endl; - } - else { - dellist_r.push_back( *it ); - } - } - } - - MIL << "ResolvablesToInsDel: delete " << dellist_r.size() - << ", install " << instlist_r.size() - << ", srcinstall " << srclist_r.size() - << ", nonpkg " << nonpkglist.size() << endl; - - /////////////////////////////////////////////////////////////////// - // - // strip packages to_delete which get obsoleted by - // to_install (i.e. delay deletion in case the - // obsoleting package likes to save whatever... - // - /////////////////////////////////////////////////////////////////// - strip_obsoleted_to_delete( dellist_r, instlist_r ); - - if ( dellist_r.size() ) { - /////////////////////////////////////////////////////////////////// - // - // sort delete list... - // - /////////////////////////////////////////////////////////////////// - TargetImpl::PoolItemSet delset( dellist_r.begin(), dellist_r.end() ); // for delete order - TargetImpl::PoolItemSet dummy; // dummy, empty, should contain already installed - - InstallOrder order( pool_r, delset, dummy ); // sort according top prereq - order.init(); - const TargetImpl::PoolItemList dsorted( order.getTopSorted() ); - - dellist_r.clear(); - for ( TargetImpl::PoolItemList::const_reverse_iterator cit = dsorted.rbegin(); - cit != dsorted.rend(); ++cit ) - { - dellist_r.push_back( *cit ); - } - } - - /////////////////////////////////////////////////////////////////// - // - // sort installed list... - // - /////////////////////////////////////////////////////////////////// - if ( instlist_r.empty() ) { - instlist_r.splice( instlist_r.end(), nonpkglist ); - - return; - } -#warning Source Rank Priority ? -#if 0 - /////////////////////////////////////////////////////////////////// - // Get desired order of InstSrc'es to install from. - /////////////////////////////////////////////////////////////////// - typedef map RankPriority; - - RankPriority rankPriority; - { - InstSrcManager::ISrcIdList sourcerank( Y2PM::instSrcManager().instOrderSources() ); - // map InstSrc rank to install priority - unsigned prio = 0; - for ( InstSrcManager::ISrcIdList::const_iterator it = sourcerank.begin(); - it != sourcerank.end(); ++it, ++prio ) { - rankPriority[(*it)->descr()->default_rank()] = prio; - } - } -#endif - - /////////////////////////////////////////////////////////////////// - // Compute install order according to packages prereq. - // Try to group packages with respect to the desired install order - /////////////////////////////////////////////////////////////////// - // backup list for debug purpose. - // You can as well build the set, clear the list and rebuild it in install order. - TargetImpl::PoolItemList instbackup_r; - instbackup_r.swap( instlist_r ); - - TargetImpl::PoolItemSet insset( instbackup_r.begin(), instbackup_r.end() ); // for install order - TargetImpl::PoolItemSet installed; // dummy, empty, should contain already installed - - InstallOrder order( pool_r, insset, installed ); - // start recursive depth-first-search - order.init(); - MIL << "order.init() done" << endl; - order.printAdj( XXX, false ); - /////////////////////////////////////////////////////////////////// - // build install list in install order - /////////////////////////////////////////////////////////////////// - TargetImpl::PoolItemList best_list; - unsigned best_prio = 0; - unsigned best_medianum = 0; - - TargetImpl::PoolItemList last_list; - unsigned last_prio = 0; - unsigned last_medianum = 0; - - TargetImpl::PoolItemList other_list; - - for ( TargetImpl::PoolItemList items = order.computeNextSet(); ! items.empty(); items = order.computeNextSet() ) - { -MIL << "order.computeNextSet: " << items.size() << " resolvables" << endl; - /////////////////////////////////////////////////////////////////// - // items contains all packages we could install now. Pick all packages - // from current media, or best media if none for current. - /////////////////////////////////////////////////////////////////// - - best_list.clear(); - last_list.clear(); - other_list.clear(); - - for ( TargetImpl::PoolItemList::iterator cit = items.begin(); cit != items.end(); ++cit ) - { - Resolvable::constPtr res( cit->resolvable() ); - if (!res) continue; - Package::constPtr cpkg( asKind(res) ); - if (!cpkg) { - XXX << "Not a package " << *cit << endl; - order.setInstalled( *cit ); - other_list.push_back( *cit ); - continue; - } - XXX << "Package " << *cpkg << ", media " << cpkg->sourceMediaNr() << " last_medianum " << last_medianum << " best_medianum " << best_medianum << endl; - if ( cpkg->source().numericId() == last_prio && - cpkg->sourceMediaNr() == last_medianum ) { - // prefer packages on current media. - last_list.push_back( *cit ); - continue; - } - - if ( last_list.empty() ) { - // check for best media as long as there are no packages for current media. - - if ( ! best_list.empty() ) { - - if ( cpkg->source().numericId() < best_prio ) { - best_list.clear(); // new best - } else if ( cpkg->source().numericId() == best_prio ) { - if ( cpkg->sourceMediaNr() < best_medianum ) { - best_list.clear(); // new best - } else if ( cpkg->sourceMediaNr() == best_medianum ) { - best_list.push_back( *cit ); // same as best -> add - continue; - } else { - continue; // worse - } - } else { - continue; // worse - } - } - - if ( best_list.empty() ) - { - // first package or new best - best_list.push_back( *cit ); - best_prio = cpkg->source().numericId(); - best_medianum = cpkg->sourceMediaNr(); - continue; - } - } - - } // for all packages in current set - - /////////////////////////////////////////////////////////////////// - // remove packages picked from install order and append them to - // install list. - /////////////////////////////////////////////////////////////////// - TargetImpl::PoolItemList & take_list( last_list.empty() ? best_list : last_list ); - if ( last_list.empty() ) - { - MIL << "SET NEW media " << best_medianum << endl; - last_prio = best_prio; - last_medianum = best_medianum; - } - else - { - MIL << "SET CONTINUE" << endl; - } - - for ( TargetImpl::PoolItemList::iterator it = take_list.begin(); it != take_list.end(); ++it ) - { - order.setInstalled( *it ); - XXX << "SET isrc " << (*it)->source().numericId() << " -> " << (*it) << endl; - } - // move everthing from take_list to the end of instlist_r, clean take_list - instlist_r.splice( instlist_r.end(), take_list ); - // same for other_list - instlist_r.splice( instlist_r.end(), other_list ); - - } // for all sets computed - - - if ( instbackup_r.size() != instlist_r.size() ) - { - ERR << "***************** Lost packages in InstallOrder sort." << endl; - } - instlist_r.splice( instlist_r.end(), nonpkglist ); -} - ///////////////////////////////////////////////////////////////// } // namespace target