- reset selections after install/remove in zypper shell
authorJan Kupec <jkupec@suse.cz>
Wed, 5 Dec 2007 12:36:20 +0000 (12:36 +0000)
committerJan Kupec <jkupec@suse.cz>
Wed, 5 Dec 2007 12:36:20 +0000 (12:36 +0000)
src/zypper-misc.cc
src/zypper-misc.h
src/zypper.cc

index 55e3142..1b17798 100644 (file)
@@ -412,6 +412,47 @@ void mark_by_capability (const Zypper & zypper,
   }
 }
 
+// ----------------------------------------------------------------------------
+
+void remove_selections(Zypper & zypper)
+{
+  MIL << "Removing user selections from the solver pool" << endl;
+
+  DBG << "Removing user setToBeInstalled()/Removed()" << endl;
+
+  // iterate pool, searching for ResStatus::isByUser()
+  // TODO optimize: remember user selections and iterate by name
+  // TODO optimize: it seems this is actually needed only if the selection was
+  //      not committed (user has chosen not to continue)
+  const ResPool & pool = God->pool();
+  cout << "pool size" << pool.size() << endl;
+  for (ResPool::const_iterator it = pool.begin(); it != pool.end(); ++it)
+    if (it->status().isByUser())
+    {
+      DBG << "Removing user setToBeInstalled()/Removed()" << endl;
+      it->status().resetTransact(zypp::ResStatus::USER);
+    }
+
+  DBG << "Removing user addRequire() addConflict()" << endl;
+
+  Resolver_Ptr solver = God->resolver();
+  CapSet capSet = solver->getConflict();
+  for (CapSet::const_iterator it = capSet.begin(); it != capSet.end(); ++it)
+  {
+    DBG << "removing conflict: " << (*it) << endl;
+    solver->removeConflict(*it);
+  }
+  capSet = solver->getRequire();
+  for (CapSet::const_iterator it = capSet.begin(); it != capSet.end(); ++it)
+  {
+    DBG << "removing require: " << (*it) << endl;
+    solver->removeRequire(*it);
+  }
+
+  MIL << "DONE" << endl;
+}
+
+// ----------------------------------------------------------------------------
 
 // debugging
 static
index 691ad2e..89df08d 100644 (file)
@@ -40,6 +40,12 @@ void mark_by_capability (const Zypper & zypper,
                         const zypp::ResObject::Kind &kind,
                         const std::string &capstr );
 
+/**
+ * Reset all selections made by mark_* methods. Needed in the shell to reset
+ * selections after the install and remove commands.
+ */
+void remove_selections(Zypper & zypper);
+
 int show_summary(Zypper & zypper);
 //std::string calculate_token();
 
index 20d5190..132343a 100644 (file)
@@ -451,6 +451,20 @@ void Zypper::commandShell()
 
 void Zypper::shellCleanup()
 {
+  MIL << "Cleaning up for the next command." << endl;
+
+  switch(command().toEnum())
+  {
+  case ZypperCommand::INSTALL_e:
+  case ZypperCommand::REMOVE_e:
+  //case Zyppercommand::UPDATE_e: TODO once the update will take arguments
+  {
+    remove_selections(*this);
+    break;
+  }
+  default:;
+  }
+
   // clear any previous arguments 
   _arguments.clear();
   // clear command options
@@ -490,7 +504,6 @@ void Zypper::safeDoCommand()
     if (exiting())
       return;
     doCommand();
-    setCommand(ZypperCommand::NONE);
   }
   catch (const AbortRequestException & ex)
   {