From f5b46557aaec8b1b5b3aa651cbbc73200e46f998 Mon Sep 17 00:00:00 2001 From: Jan Kupec Date: Wed, 5 Dec 2007 12:36:20 +0000 Subject: [PATCH] - reset selections after install/remove in zypper shell --- src/zypper-misc.cc | 41 +++++++++++++++++++++++++++++++++++++++++ src/zypper-misc.h | 6 ++++++ src/zypper.cc | 15 ++++++++++++++- 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/zypper-misc.cc b/src/zypper-misc.cc index 55e3142..1b17798 100644 --- a/src/zypper-misc.cc +++ b/src/zypper-misc.cc @@ -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 diff --git a/src/zypper-misc.h b/src/zypper-misc.h index 691ad2e..89df08d 100644 --- a/src/zypper-misc.h +++ b/src/zypper-misc.h @@ -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(); diff --git a/src/zypper.cc b/src/zypper.cc index 20d5190..132343a 100644 --- a/src/zypper.cc +++ b/src/zypper.cc @@ -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) { -- 2.7.4