#include "utils/misc.h"
#include "install.h"
-
+#include "update.h"
+#include <iostream>
using namespace std;
using namespace zypp;
using namespace boost;
extern ZYpp::Ptr God;
+/** Use ui::Selectable::theObj() or candidateObj() */
+#define USE_THE_ONE 0
+
// TODO edition, arch ?
static void mark_for_install(Zypper & zypper,
const ResObject::Kind &kind,
ui::Selectable::Ptr s = *q.selectableBegin();
+#if USE_THE_ONE
+ PoolItem candidate = s->candidateObj();
+#else
+ PoolItem candidate = findUpdateItem(God->pool(), s->installedObj());
+ if (!candidate)
+ candidate = s->installedObj();
+#endif
+
if (s->installedObj() &&
- s->installedObj().resolvable()->edition() == s->candidateObj().resolvable()->edition() &&
- s->installedObj().resolvable()->arch() == s->candidateObj().resolvable()->arch() &&
+ s->installedObj().resolvable()->edition() == candidate.resolvable()->edition() &&
+ s->installedObj().resolvable()->arch() == candidate.resolvable()->arch() &&
( ! copts.count("force") ) )
{
// if it is broken install anyway, even if it is installed
- if ( s->candidateObj().isBroken() )
- {
- s->candidateObj().status().setTransact( true, zypp::ResStatus::USER );
- }
+ if (candidate.isBroken())
+ candidate.status().setTransact(true, zypp::ResStatus::USER);
else
- {
zypper.out().info(boost::str(format(
// translators: e.g. skipping package 'zypper' (the newest version already installed)
_("skipping %s '%s' (the newest version already installed)"))
% kind_to_string_localized(kind,1) % name));
- }
}
- else {
-
+ else
+ {
//! \todo don't use setToBeInstalled for this purpose but higher level solver API
- bool result = s->candidateObj().status().setToBeInstalled( zypp::ResStatus::USER );
- if (!result)
+ if (!candidate.status().setToBeInstalled(zypp::ResStatus::USER))
{
+ cout << "no" << endl;
// this is because the resolvable is installed and we are forcing.
- s->candidateObj().status().setTransact( true, zypp::ResStatus::USER );
+ candidate.status().setTransact(true, zypp::ResStatus::USER);
if (!copts.count("force"))
{
zypper.out().error(boost::str(
DBG << endl;
}
-#define USE_THE_ONE 0
-
-#if not USE_THE_ONE
-
-// ----------------------------------------------------------------------------
-
-class LookForUpdate : public zypp::resfilter::PoolItemFilterFunctor
-{
-public:
- PoolItem best;
-
- bool operator()( PoolItem provider )
- {
- if (!provider.status().isLocked() // is not locked (taboo)
- && (!best // first match
- // or a better edition than so-far-found
- || best->edition().compare( provider->edition() ) < 0))
- {
- best = provider;
- }
- return true;
- }
-};
-
-// ----------------------------------------------------------------------------
-
-// Find best (according to edition) uninstalled item
-// with same kind/name/arch as item.
-// Similar to zypp::solver::detail::Helper::findUpdateItem
-// but allows changing the vendor
-static
-PoolItem
-findUpdateItem( const ResPool & pool, PoolItem item )
-{
- LookForUpdate info;
-
- 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<CompareByEQ<Arch> >( item->arch() ) ),
- resfilter::byEdition<CompareByGT<Edition> >( item->edition() )),
- functor::functorRef<bool,PoolItem>(info));
-
- XXX << "findArchUpdateItem(" << item << ") => " << info.best;
- return info.best;
-}
-
-#endif
-
// ----------------------------------------------------------------------------
static void
// ----------------------------------------------------------------------------
-// collect items, select best edition
-// this is used to find best available or installed.
-// The name of the class is a bit misleading though ...
-
-class LookForArchUpdate : public zypp::resfilter::PoolItemFilterFunctor
+/*
+ * Collect items, select the best edition.
+ * This is used to find the best available or installed pool item from a set.
+ */
+class SaveBetterEdition : public zypp::resfilter::PoolItemFilterFunctor
{
public:
PoolItem best;
- bool operator()( PoolItem provider )
+ bool operator()(PoolItem provider)
+ {
+ if (!provider.status().isLocked() // is not locked (taboo)
+ && (!best // first match
+ // or a better edition than so-far-found
+ || best->edition().compare(provider->edition()) < 0))
{
- if (!provider.status().isLocked() // is not locked (taboo)
- && (!best // first match
- // or a better edition than candidate
- || best->edition().compare( provider->edition() ) < 0))
- {
- best = provider; // store
- }
- return true; // keep going
+ best = provider;
}
+ return true;
+ }
};
// ----------------------------------------------------------------------------
-// Find best (according to edition) uninstalled item
-// with same kind/name/arch as item.
-// Similar to zypp::solver::detail::Helper::findUpdateItem
-// but that allows changing the arch (#222140).
-static
+// does not allow changing the arch (#222140).
PoolItem
-findArchUpdateItem( const ResPool & pool, PoolItem item )
+findUpdateItem( const ResPool & pool, PoolItem item )
{
- LookForArchUpdate info;
+ SaveBetterEdition info;
- invokeOnEach( pool.byIdentBegin( item->kind(), item->name() ),
- pool.byIdentEnd( item->kind(), item->name() ),
+ 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<CompareByEQ<Arch> >( item->arch() ) ),
- resfilter::byEdition<CompareByGT<Edition> >( item->edition() )),
- functor::functorRef<bool,PoolItem> (info) );
-
- _XDEBUG("findArchUpdateItem(" << item << ") => " << info.best);
+ functor::chain(
+ functor::chain(
+ resfilter::ByUninstalled(),
+ resfilter::byArch<CompareByEQ<Arch> >(item->arch())),
+ resfilter::byEdition<CompareByGT<Edition> >(item->edition())),
+ functor::functorRef<bool,PoolItem>(info));
+
+ XXX << "findUpdateItem(" << item << ") => " << info.best;
return info.best;
}
{
if (it->status().isUninstalled())
continue;
- // (actually similar to ProvideProcess?)
- PoolItem candidate = findArchUpdateItem( pool, *it );
+
+ PoolItem candidate = findUpdateItem( pool, *it );
if (!candidate.resolvable())
continue;
// best-effort update
// ----------------------------------------------------------------------------
-// find installed item matching passed one
-// use LookForArchUpdate as callback handler in order to cope with
-// multiple installed resolvables of the same name.
-// LookForArchUpdate will return the one with the highest edition.
-
+/*
+ * Find installed item matching passed one.
+ * Use SaveBetterEdition as callback handler in order to cope with
+ * multiple installed resolvables of the same name.
+ * SaveBetterEdition will return the one with the highest edition.
+ */
static PoolItem
findInstalledItem( PoolItem item )
{
const zypp::ResPool& pool = God->pool();
- LookForArchUpdate info;
+ SaveBetterEdition info;
invokeOnEach( pool.byIdentBegin( item->kind(), item->name() ),
pool.byIdentEnd( item->kind(), item->name() ),
resfilter::ByInstalled (),
functor::functorRef<bool,PoolItem> (info) );
- _XDEBUG("findInstalledItem(" << item << ") => " << info.best);
+ XXX << "findInstalledItem(" << item << ") => " << info.best;
return info.best;
}
for_(solvit, q.selectableBegin(), q.selectableEnd())
{
ui::Selectable::Ptr s = *solvit;
- PoolItem theone = s->theObj();
+#if USE_THE_ONE
+ PoolItem theone = s.theObj();
+#else
+ PoolItem theone;
+
+ if (s->installedEmpty())
+ theone = *s->availableBegin();
+ else
+ theone = findUpdateItem(God->pool(), *s->installedBegin());
+ if (!theone)
+ theone = *s->installedBegin();
+#endif
+
if (equalNVRA(*s->installedObj().resolvable(), *theone.resolvable()))
{
DBG << "the One (" << theone << ") is installed, skipping." << endl;