const ZypperCommand ZypperCommand::ADD_LOCK(ZypperCommand::ADD_LOCK_e);
const ZypperCommand ZypperCommand::REMOVE_LOCK(ZypperCommand::REMOVE_LOCK_e);
const ZypperCommand ZypperCommand::LIST_LOCKS(ZypperCommand::LIST_LOCKS_e);
+const ZypperCommand ZypperCommand::CLEAN_LOCKS(ZypperCommand::CLEAN_LOCKS_e);
const ZypperCommand ZypperCommand::HELP(ZypperCommand::HELP_e);
const ZypperCommand ZypperCommand::SHELL(ZypperCommand::SHELL_e);
_table["addlock"] = _table["al"] = _table["lock-add"] = _table["la"] = ZypperCommand::ADD_LOCK_e;
_table["removelock"] = _table["rl"] = _table["lock-delete"] = _table["ld"] = ZypperCommand::REMOVE_LOCK_e;
_table["locks"] = _table["ll"] = _table["lock-list"] = ZypperCommand::LIST_LOCKS_e;
+ _table["cleanlocks"] = _table["cl"] = _table["lock-clean"] = ZypperCommand::CLEAN_LOCKS_e;
_table["help"] = _table["?"] = ZypperCommand::HELP_e;
_table["shell"] = _table["sh"] = ZypperCommand::SHELL_e;
static const ZypperCommand ADD_LOCK;
static const ZypperCommand REMOVE_LOCK;
static const ZypperCommand LIST_LOCKS;
+ static const ZypperCommand CLEAN_LOCKS;
static const ZypperCommand HELP;
static const ZypperCommand SHELL;
ADD_LOCK_e,
REMOVE_LOCK_e,
LIST_LOCKS_e,
+ CLEAN_LOCKS_e,
HELP_e,
SHELL_e,
--- /dev/null
+#ifndef LOCKS_ZYPPER_CALLBACKS_H
+#define LOCKS_ZYPPER_CALLBACKS_H
+
+#include <iostream>
+
+#include "zypp/base/Logger.h"
+#include "zypp/ZYppCallbacks.h"
+#include "zypp/PoolQuery.h"
+
+#include "zypper-prompt.h"
+#include "zypper-utils.h"
+#include "output/prompt.h"
+
+namespace zypp {
+
+ struct LocksSaveReportReceiver : public zypp::callback::ReceiveReport<zypp::SavingLocksReport>
+ {
+ virtual Action conflict( const PoolQuery& query, ConflictState state )
+ {
+ //TODO localize
+ if (state==SAME_RESULTS)
+ {
+ Zypper::instance()->out().error("this query have lock same results as lock which you want remove:");
+ }
+ else
+ {
+ Zypper::instance()->out().error("this query lock some of objects, which you want unlock:");
+ }
+
+ query.serialize(std::cout);
+
+ return read_bool_answer(PROMPT_YN_REMOVE_LOCK ,
+ "Do you want remove this lock?", true)? DELETE : IGNORE;
+ }
+ };
+
+ struct CleanLocksReportReceiver : public zypp::callback::ReceiveReport<zypp::CleanEmptyLocksReport>
+ {
+ virtual Action execute( const PoolQuery& query )
+ {
+ Zypper::instance()->out().error("this query doesn't lock anything:");
+
+ query.serialize(std::cout);
+
+ return read_bool_answer(PROMPT_YN_REMOVE_LOCK ,
+ "Do you want remove this lock?", true)? DELETE : IGNORE;
+ }
+ };
+
+
+
+}
+
+class LocksCallbacks {
+ private:
+ zypp::LocksSaveReportReceiver _saveReport;
+ zypp::CleanLocksReportReceiver _cleanReport;
+
+ public:
+ LocksCallbacks()
+ {
+ _saveReport.connect();
+ _cleanReport.connect();
+ }
+
+ ~LocksCallbacks()
+ {
+ _saveReport.disconnect();
+ _cleanReport.disconnect();
+ }
+};
+
+#endif
#include "zypp/sat/SolvAttr.h"
#include "zypp/PoolQuery.h"
+#include "zypp/Locks.h"
#include "zypp/target/rpm/RpmHeader.h" // for install <.rpmURI>
break;
}
+ case ZypperCommand::CLEAN_LOCKS_e:
+ {
+ static struct option options[] =
+ {
+ {"help", no_argument, 0, 'h'},
+ {"only-duplicates", no_argument, 0, 'd' },
+ {"only-empty", no_argument, 0, 'e' },
+ {0, 0, 0, 0}
+ };
+ specific_options = options;
+ _command_help = ( //TODO localize
+ "clean locks (ll)\n"
+ "\n"
+ "Removes useless locks. Before removing locks which doesn't lock anything, ask user.\n"
+ "\n"
+ " Command options:\n"
+ "-d, --only-duplicates Clean only duplicate locks.\n"
+ "-e, --only-empty Clean only locks which doesn't lock anything.\n"
+ );
+ break;
+ }
+
case ZypperCommand::SHELL_QUIT_e:
{
static struct option quit_options[] = {
break;
}
+
+ case ZypperCommand::CLEAN_LOCKS_e:
+ {
+ if (runningHelp()) { out().info(_command_help, Out::QUIET); return; }
+
+ init_target(*this);
+ init_repos(*this);
+ if (exitCode() != ZYPPER_EXIT_OK)
+ return;
+ load_resolvables(*this);
+
+ Locks::instance().read();
+ Locks::size_type start = Locks::instance().size();
+ if ( !copts.count("only-duplicate") )
+ Locks::instance().removeEmpty();
+ if ( !copts.count("only-empty") )
+ Locks::instance().removeDuplicates();
+
+ Locks::instance().save();
+
+ out().info(str::form("removed locks: %lu",start-Locks::instance().size()));
+
+ break;
+ }
// -----------------------------( shell )------------------------------------