Author: jkupec
Date: Sun Oct 5 20:08:19 2008
New Revision: 11245
URL: http://svn.opensuse.org/viewcvs/zypp?rev=11245&view=rev
Log:
- fixed reinstall (zypper in -f foo) (bnc #421588)
Modified:
trunk/zypper/src/install.cc
Modified: trunk/zypper/src/install.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/install.cc?rev=11245&r1=11244&r2=11245&view=diff
==============================================================================
--- trunk/zypper/src/install.cc (original)
+++ trunk/zypper/src/install.cc Sun Oct 5 20:08:19 2008
@@ -9,7 +9,7 @@
#include "install.h"
#include "update.h"
-#include <iostream>
+
using namespace std;
using namespace zypp;
using namespace boost;
@@ -19,6 +19,31 @@
/** Use ui::Selectable::theObj() or candidateObj() */
#define USE_THE_ONE 0
+/** Simple functor remembering the first passed pool item and stopping the loop. */
+struct PoolItemGetter
+{
+ PoolItem item;
+ bool operator()(const PoolItem & pi)
+ { item = pi; return false; }
+};
+
+static PoolItem findInstalledItemInRepos(const PoolItem & installed)
+{
+ const zypp::ResPool& pool = God->pool();
+ PoolItemGetter getter;
+ invokeOnEach(
+ pool.byIdentBegin(installed->kind(), installed->name()),
+ pool.byIdentEnd(installed->kind(), installed->name()),
+ functor::chain(
+ functor::chain(
+ resfilter::ByUninstalled(),
+ resfilter::byEdition(installed->edition())),
+ resfilter::byArch(installed->arch())),
+ functor::functorRef(getter));
+ XXX << "findInstalledItemInRepos(" << installed << ") => " << getter.item << endl;
+ return getter.item;
+}
+
// TODO edition, arch ?
static void mark_for_install(Zypper & zypper,
const ResObject::Kind &kind,
@@ -50,45 +75,54 @@
}
ui::Selectable::Ptr s = *q.selectableBegin();
+ bool force = copts.count("force");
#if USE_THE_ONE
PoolItem candidate = s->candidateObj();
#else
PoolItem candidate = findUpdateItem(God->pool(), s->installedObj());
if (!candidate)
- candidate = s->installedObj();
+ {
+ if (force)
+ {
+ candidate = findInstalledItemInRepos(s->installedObj());
+ if (!candidate)
+ {
+ zypper.out().info(str::form(
+ // translators: %s-%s.%s is name-version.arch
+ _("Package %s-%s.%s not found in repositories, cannot reinstall."),
+ s->name().c_str(), s->installedObj().resolvable()->edition().c_str(),
+ s->installedObj().resolvable()->arch().c_str()));
+ zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+ return;
+ }
+ }
+ else
+ candidate = s->installedObj();
+ }
#endif
if (s->installedObj() &&
s->installedObj().resolvable()->edition() == candidate.resolvable()->edition() &&
s->installedObj().resolvable()->arch() == candidate.resolvable()->arch() &&
- ( ! copts.count("force") ) )
+ !force)
{
// if it is broken install anyway, even if it is installed
if (candidate.isBroken())
- candidate.status().setTransact(true, zypp::ResStatus::USER);
+ candidate.status().setToBeInstalled(zypp::ResStatus::USER);
else
zypper.out().info(boost::str(format(
- // translators: e.g. skipping package 'zypper' (the newest version already installed)
+ // translators: e.g. skipping package 'zypper' (the newest version already installed)
+ //! \todo capitalize the first letter
_("skipping %s '%s' (the newest version already installed)"))
% kind_to_string_localized(kind,1) % name));
}
- else
+ else if (!candidate.status().setToBeInstalled(zypp::ResStatus::USER) && !force)
{
- //! \todo don't use setToBeInstalled for this purpose but higher level solver API
- if (!candidate.status().setToBeInstalled(zypp::ResStatus::USER))
- {
- cout << "no" << endl;
- // this is because the resolvable is installed and we are forcing.
- candidate.status().setTransact(true, zypp::ResStatus::USER);
- if (!copts.count("force"))
- {
- zypper.out().error(boost::str(
- format(_("Failed to add '%s' to the list of packages to be installed."))
- % name));
- ERR << "Could not set " << name << " as to-be-installed" << endl;
- }
- }
+ zypper.out().error(boost::str(
+ format(_("Failed to add '%s' to the list of packages to be installed."))
+ % name));
+ ERR << "Could not set " << name << " as to-be-installed" << endl;
}
}
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org