ref: refs/heads/master
commit 259c83e196277137097ae5fbeeb2c48d8fbaaf2f
Author: Ján Kupec
Date: Mon Sep 28 16:12:43 2009 +0200
Replaced deprecated findUpdateItem with zypp::ui::Selectable::updateCandidateObj
---
src/info.cc | 10 ++----
src/install.cc | 37 ++++++++-----------
src/update.cc | 107 +++++--------------------------------------------------
src/update.h | 21 -----------
4 files changed, 29 insertions(+), 146 deletions(-)
diff --git a/src/info.cc b/src/info.cc
index 92ff694..dc4a043 100644
--- a/src/info.cc
+++ b/src/info.cc
@@ -33,7 +33,6 @@ using boost::format;
extern ZYpp::Ptr God;
-#define USE_THE_ONE 0
void printNVA(const ResObject::constPtr & res)
{
@@ -171,12 +170,9 @@ Copy and modify /usr/share/vim/current/gvimrc to ~/.gvimrc if needed.
void printPkgInfo(Zypper & zypper, const ui::Selectable & s)
{
PoolItem installed = s.installedObj();
-
-#if USE_THE_ONE
- PoolItem theone = s.theObj();
-#else
- PoolItem theone = findTheBest(God->pool(), s);
-#endif
+ PoolItem theone = s.updateCandidateObj();
+ if (!theone)
+ theone = installed;
cout << (zypper.globalOpts().is_rug_compatible ? _("Catalog: ") : _("Repository: "))
<< theone.resolvable()->repository().info().name() << endl;
diff --git a/src/install.cc b/src/install.cc
index a9b3240..2cb9482 100755
--- a/src/install.cc
+++ b/src/install.cc
@@ -19,8 +19,6 @@ using namespace boost;
extern ZYpp::Ptr God;
-/** Use ui::Selectable::theObj() or candidateObj() */
-#define USE_THE_ONE 0
static PoolItem findInstalledItemInRepos(const PoolItem & installed)
{
@@ -32,7 +30,7 @@ static PoolItem findInstalledItemInRepos(const PoolItem & installed)
filter::SameItemAs(installed),
resfilter::ByUninstalled()),
functor::getFirst(result));
- INT << "findInstalledItemInRepos(" << installed << ") => " << result << endl;
+ XXX << "findInstalledItemInRepos(" << installed << ") => " << result << endl;
return result;
}
@@ -79,20 +77,13 @@ mark_for_install(Zypper & zypper,
ui::Selectable::Ptr s = *q.selectableBegin();
DBG << "... done" << endl;
-/*
- for_(it, s->installedBegin(), s->installedEnd())
- { cout << *it << endl; }
- for_(it, s->availableBegin(), s->availableEnd())
- { cout << *it << endl; }
-*/
+
bool force = copts.count("force");
-#if USE_THE_ONE
- PoolItem candidate = s->candidateObj();
-#else
- PoolItem candidate = findTheBest(God->pool(), *s);
-#endif
+ PoolItem candidate = s->updateCandidateObj();
+ if (!candidate)
+ candidate = s->installedObj();
if (s->installedObj() &&
equalNVRA(*s->installedObj().resolvable(), *candidate.resolvable()) &&
@@ -300,11 +291,9 @@ mark_selectable(Zypper & zypper,
const string & repo = "",
const string & arch = "")
{
-#if USE_THE_ONE
- PoolItem theone = s.theObj();
-#else
- PoolItem theone = findTheBest(God->pool(), s);
-#endif
+ PoolItem theone = s.updateCandidateObj();
+ if (!theone)
+ theone = s.installedObj();
DBG << "the One: " << theone << endl;
@@ -373,7 +362,7 @@ mark_selectable(Zypper & zypper,
{
if (theoneinstalled && !force)
{
- DBG << "the One (" << theone << ") is installed, skipping." << endl;
+ DBG << "the One (" << theone << ") is already installed, skipping." << endl;
zypper.out().info(str::form(
_("'%s' is already installed."), s.name().c_str()));
return;
@@ -395,7 +384,13 @@ mark_selectable(Zypper & zypper,
//! could be a problem for patches if there would a greater version
//! of a patch appear that would be irrelevant at the same time. Should
- //! happen probably.
+ //! not happen usually.
+
+ //! this causes bnc #539360 if wrong update candidate is found
+ //! this request installation of installed > installed_version, which
+ //! can drag in a package with higher version even from repo with lower
+ //! priority
+ //! hopefully using ui::Selectable::updateCandidateObj() will fix this
if (anyinstalled)
c = Capability(s.name(), Rel::GT, installed->edition(), s.kind());
// require any version
diff --git a/src/update.cc b/src/update.cc
index 606f9a8..8817910 100755
--- a/src/update.cc
+++ b/src/update.cc
@@ -300,89 +300,6 @@ public:
// ----------------------------------------------------------------------------
-// does not allow changing the arch (#222140)
-// except noarch->any or any->noarch (bnc #483179)
-// TODO: ignores priority (bnc #464458)
-// TODO: move to libzypp
-PoolItem
-findUpdateItem( const ResPool & pool, const PoolItem item )
-{
- SaveBetterEdition info;
-
- // look for the same arch, best version
- invokeOnEach( pool.byIdentBegin(item->kind(), item->name()),
- pool.byIdentEnd(item->kind(), item->name()),
- // get uninstalled, equal kind and arch, better edition
- functor::chain(
- functor::chain(
- resfilter::ByUninstalled(),
- resfilter::byArch(item->arch())),
- resfilter::byEdition(item->edition())),
- functor::functorRef(info));
-
- // the item is noarch, look for best arch, best version
- // (noarch -> any is allowed) (bnc #483179)
- if (item->arch() == Arch_noarch)
- {
- SaveBetterEditionArch bestEA;
- invokeOnEach( pool.byIdentBegin(item->kind(), item->name()),
- pool.byIdentEnd(item->kind(), item->name()),
- // get uninstalled, equal kind, better edition
- functor::chain(
- resfilter::ByUninstalled(),
- resfilter::byEdition(item->edition())),
- functor::functorRef(bestEA));
- if (bestEA.best)
- {
- if (!info.best)
- info.best = bestEA.best;
- if (info.best->arch().compare(bestEA.best->arch()) < 0)
- info.best = bestEA.best;
- }
- }
- // the item is not noarch & no update found so far - try looking for a noarch
- // package (any -> noarch is allowed) (bnc #483179)
- else if (!info.best)
- {
- invokeOnEach( pool.byIdentBegin(item->kind(), item->name()),
- pool.byIdentEnd(item->kind(), item->name()),
- // get uninstalled, equal kind and arch, better edition
- functor::chain(
- functor::chain(
- resfilter::ByUninstalled(),
- resfilter::byArch(Arch_noarch)),
- resfilter::byEdition(item->edition())),
- functor::functorRef(info));
- }
-
- XXX << "findUpdateItem(" << item << ") => " << info.best;
- return info.best;
-}
-
-PoolItem
-findTheBest( const ResPool & pool, const ui::Selectable & s)
-{
- PoolItem theone;
- if (s.installedEmpty())
- //! FIXME this will pick a random arch - should pick the system arch, or
- //! the best compatible.
- theone = findUpdateItem(God->pool(), *s.availableBegin());
- else
- theone = findUpdateItem(God->pool(), *s.installedBegin());
-
- if (!theone)
- {
- if (s.installedEmpty())
- theone = *s.availableBegin();
- else
- theone = *s.installedBegin();
- }
-
- return theone;
-}
-
-// ----------------------------------------------------------------------------
-
/**
* Find all available updates of given kind.
*/
@@ -407,20 +324,18 @@ find_updates( const ResKind & kind, Candidates & candidates )
return;
}
- ResPool::byKind_iterator
- it = pool.byKindBegin (kind),
- e = pool.byKindEnd (kind);
- for (; it != e; ++it)
+
+ for_(it, pool.proxy().byKindBegin(kind), pool.proxy().byKindEnd(kind))
{
- if (it->status().isUninstalled())
+ if ((*it)->hasInstalledObj())
continue;
- PoolItem candidate = findUpdateItem( pool, *it );
- if (!candidate.resolvable())
+ PoolItem candidate = (*it)->updateCandidateObj();
+ if (!candidate)
continue;
- DBG << "item " << *it << endl;
- DBG << "cand " << candidate << endl;
+ DBG << "selectable: " << **it << endl;
+ DBG << "candidate: " << candidate << endl;
candidates.insert (candidate);
}
}
@@ -813,11 +728,9 @@ void mark_updates(Zypper & zypper, const ResKindSet & kinds, bool skip_interacti
for_(solvit, q.selectableBegin(), q.selectableEnd())
{
ui::Selectable::Ptr s = *solvit;
-#if USE_THE_ONE
- PoolItem theone = s.theObj();
-#else
- PoolItem theone = findTheBest(God->pool(), *s);
-#endif
+ PoolItem theone = s->updateCandidateObj();
+ if (!theone)
+ theone = s->installedObj();
if (equalNVRA(*s->installedObj().resolvable(), *theone.resolvable()))
{
diff --git a/src/update.h b/src/update.h
index 2f4c8b1..9f6a734 100755
--- a/src/update.h
+++ b/src/update.h
@@ -47,24 +47,3 @@ void mark_updates(Zypper & zypper,
* in --cve or --bugzilla or --bz.
*/
void mark_updates_by_issue(Zypper & zypper);
-
-/**
- * Find best (according to edition) uninstalled item
- * with same kind/name/arch as \a item.
- *
- * Similar to zypp::solver::detail::Helper::findUpdateItem()
- * but allows changing the vendor and does not allow chaning arch.
- */
-# warning get rid of findUpdateItem, make new API in zypp
-zypp::PoolItem findUpdateItem(const zypp::ResPool & pool, const zypp::PoolItem item);
-
-/**
- * Finds the best object in the Selectable.
- *
- * \todo FIXME if there is no installed object in the selectable, it chooses
- * a random arch from the available objects (the availableBegin()). Choose
- * the best compatible instead.
- * \todo All of this should be done in libzypp, using defined policies.
- */
-# warning get rid of findTheBest, make new API in zypp
-zypp::PoolItem findTheBest( const zypp::ResPool & pool, const zypp::ui::Selectable & s);
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org