From fcf8e293dd83248e7886ed204364fbc9f77667f6 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Tue, 22 Sep 2009 20:32:03 +0200 Subject: [PATCH] Add Selectable::updateCandidateObj returning the candidate for update, if there is one. --- zypp/ui/Selectable.cc | 3 +++ zypp/ui/Selectable.h | 11 ++++++++++- zypp/ui/SelectableImpl.h | 35 ++++++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/zypp/ui/Selectable.cc b/zypp/ui/Selectable.cc index 2588faa..62bf2ea 100644 --- a/zypp/ui/Selectable.cc +++ b/zypp/ui/Selectable.cc @@ -73,6 +73,9 @@ namespace zypp PoolItem Selectable::candidateObj() const { return _pimpl->candidateObj(); } + PoolItem Selectable::updateCandidateObj() const + { return _pimpl->updateCandidateObj(); } + PoolItem Selectable::setCandidate( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r ) { return _pimpl->setCandidate( newCandidate_r, causer_r ); } diff --git a/zypp/ui/Selectable.h b/zypp/ui/Selectable.h index a300eaa..c5cd548 100644 --- a/zypp/ui/Selectable.h +++ b/zypp/ui/Selectable.h @@ -120,10 +120,19 @@ namespace zypp PoolItem installedObj() const; /** The 'best' or 'most interesting' among all available objects. - * One that is, or is likely to be, chosen for installation. + * One that is, or is likely to be, chosen for installation, unless + * it violated any solver policy (see \ref updateCandidateObj). */ PoolItem candidateObj() const; + /** The best candidate for update, if there is one. + * In contrary to \ref candidateObj, this may return no item even if + * there are available objects. This simply means the best object is + * already installed, and all available objects violate at least one + * update policy. + */ + PoolItem updateCandidateObj() const; + /** Return the \ref installedObj resolvable casted to a specific kind. * \code * Selectable mySelectable; diff --git a/zypp/ui/SelectableImpl.h b/zypp/ui/SelectableImpl.h index 8b71ae7..53f4db8 100644 --- a/zypp/ui/SelectableImpl.h +++ b/zypp/ui/SelectableImpl.h @@ -117,6 +117,39 @@ namespace zypp */ PoolItem setCandidate( const PoolItem & newCandidate_r, ResStatus::TransactByValue causer_r ); + /** The best candidate for update, if there is one. + * In contrary to \ref candidateObj, this may return no item even if + * there are available objects. This simply means the best object is + * already installed, and all available objects violate at least one + * update policy. + */ + PoolItem updateCandidateObj() const + { + if ( installedEmpty() || ! _defaultCandidate ) + return _defaultCandidate; + // Here: installed and _defaultCandidate are non NULL. + + // update candidate must come from the highest priority repo + if ( _defaultCandidate->repoInfo().priority() != (*availableBegin())->repoInfo().priority() ) + return PoolItem(); + + PoolItem installed( installedObj() ); + // check vendor change + if ( ! ( ZConfig::instance().solver_allowVendorChange() + || VendorAttr::instance().equivalent( _defaultCandidate->vendor(), installed->vendor() ) ) ) + return PoolItem(); + + // check arch change + if ( _defaultCandidate->arch() != installed->arch() ) + return PoolItem(); + + // check greater edition + if ( _defaultCandidate->edition() <= installed->edition() ) + return PoolItem(); + + return _defaultCandidate; + } + /** Best among all objects. */ PoolItem theObj() const { @@ -141,7 +174,6 @@ namespace zypp available_const_iterator availableBegin() const { return _availableItems.begin(); } - available_const_iterator availableEnd() const { return _availableItems.end(); } @@ -263,6 +295,7 @@ namespace zypp AvailableItemSet _availableItems; //! Best among availabe with restpect to installed. PoolItem _defaultCandidate; + //! The object selected by setCandidateObj() method. PoolItem _candidate; }; -- 2.7.4