zypper commandline args must not silently overrule locks (bnc#742633,bnc#788863)
authorMichael Andres <ma@suse.de>
Thu, 7 Feb 2013 13:29:25 +0000 (14:29 +0100)
committerMichael Andres <ma@suse.de>
Thu, 7 Feb 2013 13:29:38 +0000 (14:29 +0100)
src/RequestFeedback.cc
src/SolverRequester.cc

index 1776864..8f95e17 100644 (file)
@@ -244,6 +244,15 @@ string SolverRequester::Feedback::asUserString(
     return str::form(_("Selecting '%s' for removal."),
         resolvable_user_string(*_objsel.resolvable()).c_str());
 
+  case INSTALLED_LOCKED:
+  {
+    ostringstream cmdhint;
+    cmdhint << "zypper removelock " << _objsel->name();
+    return str::form(
+        _("'%s' is locked. Use '%s' to unlock it."),
+        _objsel->name().c_str(), cmdhint.str().c_str());
+  }
+
   case ADDED_REQUIREMENT:
     return str::form(_("Adding requirement: '%s'."), _reqpkg.parsed_cap.asString().c_str());
 
@@ -291,6 +300,9 @@ void SolverRequester::Feedback::print(
   case ADDED_CONFLICT:
     out.info(asUserString(opts), Out::HIGH);
     break;
+  case INSTALLED_LOCKED:
+    out.warning(asUserString(opts), Out::HIGH);
+    break;
   case PATCH_INTERACTIVE_SKIPPED:
     out.warning(asUserString(opts));
     break;
index eda8def..fd376c5 100644 (file)
@@ -617,6 +617,21 @@ void SolverRequester::setToInstall(const PoolItem & pi)
     pi.status().setToBeInstalled(ResStatus::USER);
     addFeedback(Feedback::FORCED_INSTALL, PackageSpec(), pi);
   }
+  else if ( asSelectable()(pi)->locked() )
+  {
+    // Workaround: Use a solver request instead of selecting the item.
+    // This will enable the solver to report the lock conflict, while
+    // selecting the item will silently remove the lock.
+    // Basically the right way but zypp solver job API needs polishing
+    // as ther are better jobs than 'addRequire'.
+    sat::Solvable solv( pi.satSolvable() );
+    Capability cap( solv.arch(), solv.name(), Rel::EQ, solv.edition(), solv.kind() );
+    zypp::getZYpp()->resolver()->addRequire( cap );
+    _requires.insert( cap );
+    addFeedback(Feedback::SET_TO_INSTALL, PackageSpec(), pi);
+    addFeedback(Feedback::INSTALLED_LOCKED, PackageSpec(), pi);
+    return;
+  }
   else
   {
     asSelectable()(pi)->setOnSystem(pi, ResStatus::USER);
@@ -629,6 +644,21 @@ void SolverRequester::setToInstall(const PoolItem & pi)
 
 void SolverRequester::setToRemove(const zypp::PoolItem & pi)
 {
+  if ( asSelectable()(pi)->locked() )
+  {
+    // Workaround: Use a solver request instead of selecting the item.
+    // This will enable the solver to report the lock conflict, while
+    // selecting the item will silently remove the lock.
+    // Basically the right way but zypp solver job API needs polishing
+    // as ther are better jobs than 'addRequire'.
+    sat::Solvable solv( pi.satSolvable() );
+    Capability cap( solv.arch(), solv.name(), Rel::EQ, solv.edition(), solv.kind() );
+    zypp::getZYpp()->resolver()->addConflict( cap );
+    _conflicts.insert( cap );
+    addFeedback(Feedback::SET_TO_REMOVE, PackageSpec(), pi);
+    addFeedback(Feedback::INSTALLED_LOCKED, PackageSpec(), pi);
+    return;
+  }
   pi.status().setToBeUninstalled(ResStatus::USER);
   addFeedback(Feedback::SET_TO_REMOVE, PackageSpec(), pi);
   _toremove.insert(pi);