From e4491cca18956aaf7cf5cfbb6042915b72c43580 Mon Sep 17 00:00:00 2001 From: Stefan Schubert Date: Mon, 31 Mar 2008 13:39:26 +0000 Subject: [PATCH] added doUpdate( ) which Update to newest packages --- zypp/Resolver.cc | 2 + zypp/Resolver.h | 15 +++++- zypp/sat/SATResolver.cc | 83 ++++++++++++++++++++++++++++++++++ zypp/sat/SATResolver.h | 1 + zypp/solver/detail/Resolver.cc | 11 +++++ zypp/solver/detail/Resolver.h | 1 + 6 files changed, 112 insertions(+), 1 deletion(-) diff --git a/zypp/Resolver.cc b/zypp/Resolver.cc index a0b15ed76..101501a0f 100644 --- a/zypp/Resolver.cc +++ b/zypp/Resolver.cc @@ -71,6 +71,8 @@ namespace zypp { _pimpl->applySolutions (solutions); } void Resolver::doUpgrade( UpgradeStatistics & opt_stats_r ) { _pimpl->doUpgrade(opt_stats_r); } + void Resolver::doUpdate() + { _pimpl->doUpdate(); } void Resolver::setForceResolve( const bool force ) { _pimpl->setForceResolve( force ); } bool Resolver::forceResolve() diff --git a/zypp/Resolver.h b/zypp/Resolver.h index 4c0fe348d..b94ba91dc 100644 --- a/zypp/Resolver.h +++ b/zypp/Resolver.h @@ -83,7 +83,8 @@ namespace zypp * This will run a full upgrade on the pool, taking all upgrade * dependencies (provide/obsolete for package renames, split- * provides, etc.) into account and actually removing installed - * packages if no upgrade exists. + * packages if no upgrade exists AND the package dependency is + * broken * * To be run with great caution. It basically brings your * system 'back to start'. @@ -92,6 +93,18 @@ namespace zypp **/ void doUpgrade( UpgradeStatistics & opt_stats_r ); + /** + * Update to newest package + * + * Install the newest version of your installed packages as + * far as possible. This means a newer package will NOT be + * installed if it generates dependency problems. + * So the user will not get an error message. + * + **/ + void doUpdate( ); + + /** * Return the list of problematic update items * i.e. locked ones (due to foreign vendor) diff --git a/zypp/sat/SATResolver.cc b/zypp/sat/SATResolver.cc index 36821b25a..14df483af 100644 --- a/zypp/sat/SATResolver.cc +++ b/zypp/sat/SATResolver.cc @@ -558,6 +558,89 @@ SATResolver::resolvePool(const CapabilitySet & requires_caps, } +bool SATResolver::doUpdate() +{ + MIL << "SATResolver::doUpdate()" << endl; + + if (_solv) { + // remove old stuff + solver_free(_solv); + _solv = NULL; + queue_free( &(_jobQueue) ); + } + + queue_init( &_jobQueue ); + + _solv = solver_create( _SATPool, sat::Pool::instance().systemRepo().get() ); + _solv->vendorCheckCb = &vendorCheck; + + _solv->updatesystem = true; + _solv->dontinstallrecommended = true; // #FIXME dontinstallrecommended maybe set to false if it works correctly + + sat::Pool::instance().prepare(); + + // Solve ! + MIL << "Starting solving...." << endl; + solver_solve( _solv, &(_jobQueue) ); + MIL << "....Solver end" << endl; + + // copying solution back to zypp pool + //----------------------------------------- + + /* solvables to be installed */ + for (int i = 0; i < _solv->decisionq.count; i++) + { + Id p; + p = _solv->decisionq.elements[i]; + if (p < 0 || !sat::Solvable(p)) + continue; + if (sat::Solvable(p).repository().get() == _solv->installed) + continue; + + PoolItem poolItem = _pool.find (sat::Solvable(p)); + if (poolItem) { + SATSolutionToPool (poolItem, ResStatus::toBeInstalled, ResStatus::SOLVER); + } else { + ERR << "id " << p << " not found in ZYPP pool." << endl; + } + } + + /* solvables to be erased */ + for (int i = _solv->installed->start; i < _solv->installed->start + _solv->installed->nsolvables; i++) + { + if (_solv->decisionmap[i] > 0) + continue; + + PoolItem poolItem = _pool.find (sat::Solvable(i)); + if (poolItem) { + // Check if this is an update + CheckIfUpdate info; + invokeOnEach( _pool.byIdentBegin( poolItem ), + _pool.byIdentEnd( poolItem ), + resfilter::ByUninstalled(), // ByUninstalled + functor::functorRef (info) ); + + if (info.is_updated) { + SATSolutionToPool (poolItem, ResStatus::toBeUninstalledDueToUpgrade , ResStatus::SOLVER); + } else { + SATSolutionToPool (poolItem, ResStatus::toBeUninstalled, ResStatus::SOLVER); + } + } else { + ERR << "id " << i << " not found in ZYPP pool." << endl; + } + } + + // cleanup + solver_free(_solv); + _solv = NULL; + queue_free( &(_jobQueue) ); + + MIL << "SATResolver::doUpdate() done" << endl; + return true; +} + + + //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- // error handling diff --git a/zypp/sat/SATResolver.h b/zypp/sat/SATResolver.h index 43210de2c..0ea8b0473 100644 --- a/zypp/sat/SATResolver.h +++ b/zypp/sat/SATResolver.h @@ -99,6 +99,7 @@ class SATResolver : public base::ReferenceCounted, private base::NonCopyable { bool resolvePool(const CapabilitySet & requires_caps, const CapabilitySet & conflict_caps); + bool doUpdate(); ResolverProblemList problems (); void applySolutions (const ProblemSolutionList &solutions); diff --git a/zypp/solver/detail/Resolver.cc b/zypp/solver/detail/Resolver.cc index a96777232..47ae82ffb 100644 --- a/zypp/solver/detail/Resolver.cc +++ b/zypp/solver/detail/Resolver.cc @@ -103,6 +103,17 @@ Resolver::reset (bool keepExtras ) } } +bool +Resolver::doUpdate() +{ + if (_satResolver) { + return _satResolver->doUpdate(); + } else { + ERR << "SAT solver has not been initialized." << endl; + return false; + } +} + void Resolver::addExtraRequire (const Capability & capability) { diff --git a/zypp/solver/detail/Resolver.h b/zypp/solver/detail/Resolver.h index c057e2212..a88ff7fcb 100644 --- a/zypp/solver/detail/Resolver.h +++ b/zypp/solver/detail/Resolver.h @@ -163,6 +163,7 @@ class Resolver : public base::ReferenceCounted, private base::NonCopyable { bool verifySystem (); bool resolvePool(); + bool doUpdate(); void doUpgrade( zypp::UpgradeStatistics & opt_stats_r ); PoolItemList problematicUpdateItems( void ) const { return _problem_items; } -- 2.34.1