more --force fixes (bnc #483426)
authorJán Kupec <jkupec@suse.cz>
Wed, 20 Oct 2010 12:15:09 +0000 (14:15 +0200)
committerJán Kupec <jkupec@suse.cz>
Wed, 20 Oct 2010 12:15:09 +0000 (14:15 +0200)
- plain pkgname (no EVRA) to try to install the highest version
  regardless of vendor/deps/locks etc.

src/RequestFeedback.cc
src/SolverRequester.cc
src/SolverRequester.h
src/Zypper.h
tests/SolverRequester_test.cc
tests/lib/TestSetup.h

index 3948b5e..cb605c0 100644 (file)
@@ -154,6 +154,14 @@ string SolverRequester::Feedback::asUserString(
         _objinst->name().c_str(), cmdhint.str().c_str());
   }
 
+  case NOT_IN_REPOS:
+  {
+    return str::form(
+        _("Package '%s' is not available in your repositories."
+          " Cannot reinstall, upgrade, or downgrade."),
+        _objinst->name().c_str());
+  }
+
   case SELECTED_IS_OLDER:
   {
     ostringstream cmdhint;
@@ -252,6 +260,7 @@ void SolverRequester::Feedback::print(
   case UPD_CANDIDATE_CHANGES_VENDOR:
   case UPD_CANDIDATE_HAS_LOWER_PRIO:
   case UPD_CANDIDATE_IS_LOCKED:
+  case NOT_IN_REPOS:
   case SELECTED_IS_OLDER:
   case PATCH_NOT_NEEDED:
   case PATCH_UNWANTED:
index 8052bdb..07d6f5f 100644 (file)
@@ -157,6 +157,15 @@ void SolverRequester::install(const PackageSpec & pkg)
           PoolItem instobj = get_installed_obj(s);
           if (instobj)
           {
+            if (s->availableEmpty())
+            {
+              if (!_opts.force)
+                addFeedback(Feedback::ALREADY_INSTALLED, pkg, instobj, instobj);
+              addFeedback(Feedback::NOT_IN_REPOS, pkg, instobj, instobj);
+              MIL << s->name() << " not in repos, can't (re)install" << endl;
+              return;
+            }
+
             // whether user requested specific repo/version/arch
             bool userconstraints =
                 pkg.parsed_cap.detail().isVersioned()
@@ -171,6 +180,8 @@ void SolverRequester::install(const PackageSpec & pkg)
             PoolItem best;
             if (userconstraints)
               updateTo(pkg, *sit);
+            else if (_opts.force)
+                updateTo(pkg, s->highestAvailableVersionObj());
             else if ((best = s->updateCandidateObj()))
               updateTo(pkg, best);
             else if (changes_vendor && !_opts.allow_vendor_change)
index f7647b5..3d953dc 100644 (file)
@@ -132,6 +132,12 @@ public:
       UPD_CANDIDATE_IS_LOCKED,
 
       /**
+       * The installed package is no longer available in repositories.
+       * => can't reinstall, can't update/downgrade..
+       */
+      NOT_IN_REPOS,
+
+      /**
        * Selected object is not the highest available, because of user
        * restrictions like repo(s), version, architecture.
        */
index 50ef29e..09a707b 100644 (file)
@@ -171,6 +171,7 @@ public:
   Out & out();
   Config & config() { return _config; }
   const GlobalOptions & globalOpts() const { return _gopts; }
+  GlobalOptions & globalOptsNoConst() { return _gopts; }
   const parsed_opts & cOpts() const { return _copts; }
   const ZypperCommand & command() const { return _command; }
   const std::string & commandHelp() const { return _command_help; }
index 138f28c..d8cc2e7 100644 (file)
@@ -311,7 +311,7 @@ BOOST_AUTO_TEST_CASE(install10)
   sr.install(rawargs);
 
   BOOST_CHECK(sr.hasFeedback(SolverRequester::Feedback::ALREADY_INSTALLED));
-  BOOST_CHECK(sr.hasFeedback(SolverRequester::Feedback::NO_UPD_CANDIDATE));
+  BOOST_CHECK(sr.hasFeedback(SolverRequester::Feedback::NOT_IN_REPOS));
 }
 
 // request : install diffutils
index b90bd3a..011c26e 100644 (file)
@@ -21,6 +21,8 @@ using boost::unit_test::test_case;
 #include "zypp/Target.h"
 #include "zypp/ResPool.h"
 
+#include "Zypper.h"
+
 using std::cin;
 using std::cout;
 using std::cerr;
@@ -399,6 +401,13 @@ class TestSetup
           filesystem::clean_dir( _rootdir );
       }
 
+
+      Zypper & zypper = *Zypper::instance();
+      zypper.globalOptsNoConst().root_dir = _rootdir.asString();
+      zypper.globalOptsNoConst().rm_options = zypp::RepoManagerOptions(_rootdir.asString());
+      zypper.globalOptsNoConst().rm_options.knownReposPath = _rootdir / "repos.d";
+
+
       if ( ! sysarch_r.empty() )
         ZConfig::instance().setSystemArchitecture( sysarch_r );
       USR << "CREATED TESTSETUP below " << _rootdir << endl;