From b71a493fa0679d26a60e922e494a55c9115ae289 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Thu, 12 Jun 2008 08:54:11 +0000 Subject: [PATCH] - support multiple arguments to add/remove lock (bnc #398844) - enable specify repository for add/remove lock - read only locks file, apply is not needed - doesn't initialize pool for add repo (bnc #398839) --- package/zypper.changes | 9 ++++ src/zypper-locks.cc | 135 +++++++++++++++++++++++++++++++------------------ src/zypper-misc.cc | 4 +- src/zypper.cc | 19 ++----- 4 files changed, 101 insertions(+), 66 deletions(-) diff --git a/package/zypper.changes b/package/zypper.changes index 2305054..f8dfdd4 100644 --- a/package/zypper.changes +++ b/package/zypper.changes @@ -1,4 +1,13 @@ ------------------------------------------------------------------- +Thu Jun 12 10:13:02 CEST 2008 - jreidinger@suse.cz + +- support multiple arguments to add/remove lock (bnc #398844) +- enable specify repository for add/remove lock +- read only locks file, apply is not needed +- doesn't initialize pool for add repo (bnc #398839) +- r10370 + +------------------------------------------------------------------- Thu Jun 5 16:37:36 CEST 2008 - jkupec@suse.cz - fix installation of patches/patterns/products (bnc #395326) diff --git a/src/zypper-locks.cc b/src/zypper-locks.cc index ddfd7e6..c757e17 100644 --- a/src/zypper-locks.cc +++ b/src/zypper-locks.cc @@ -2,6 +2,7 @@ #include #include "zypp/base/String.h" +#include "zypp/base/Logger.h" #include "zypp/Locks.h" #include "output/Out.h" @@ -9,6 +10,7 @@ #include "zypper-tabulator.h" #include "zypper-utils.h" #include "zypper-locks.h" +#include "zypper-repos.h" using namespace zypp; using namespace std; @@ -116,18 +118,34 @@ void add_locks(Zypper & zypper, const Zypper::ArgList & args, const ResKindSet & Locks::size_type start = 0; try { - PoolQuery q; - q.addAttribute(sat::SolvAttr::name, args[0]); - for_(it, kinds.begin(), kinds.end()) - q.addKind(*it); - q.setMatchGlob(); - //! \todo addRepo() - q.setCaseSensitive(); Locks & locks = Locks::instance(); - locks.readAndApply(); + locks.read(); start = locks.size(); - locks.addLock(q); + for_(it,args.begin(),args.end()) + { + PoolQuery q; + q.addAttribute(sat::SolvAttr::name, *it); + for_(itk, kinds.begin(), kinds.end()) + q.addKind(*itk); + q.setMatchGlob(); + parsed_opts::const_iterator itr; + //TODO rug compatibility for more arguments with version restrict + if ((itr = copts.find("repo")) != copts.end()) + { + for_(it_repo,itr->second.begin(), itr->second.end()) + { + RepoInfo info; + if( match_repo( zypper, *it_repo, &info)) + q.addRepo(info.alias()); + else //TODO some error handling + WAR << "unknown repository" << *it_repo << endl; + } + } + q.setCaseSensitive(); + + locks.addLock(q); + } locks.save(); } catch(const Exception & e) @@ -137,7 +155,7 @@ void add_locks(Zypper & zypper, const Zypper::ArgList & args, const ResKindSet & zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP); } if ( start != Locks::instance().size() ) - zypper.out().info(_("Specified lock has been successfully added.")); + zypper.out().info(_("Specified lock(-s) has been successfully added.")); } @@ -146,60 +164,77 @@ void remove_locks(Zypper & zypper, const Zypper::ArgList & args) try { Locks & locks = Locks::instance(); - locks.readAndApply(); + locks.read(); Locks::size_type start = locks.size(); - Locks::const_iterator it = locks.begin(); - Locks::LockList::size_type i = 0; - safe_lexical_cast(args[0], i); - if (i > 0 && i <= locks.size()) + for_( args_it, args.begin(), args.end() ) { - advance(it, i-1); - locks.removeLock(*it); - locks.save(); + Locks::const_iterator it = locks.begin(); + Locks::LockList::size_type i = 0; + safe_lexical_cast(*args_it, i); + if (i > 0 && i <= locks.size()) + { + advance(it, i-1); + locks.removeLock(*it); - zypper.out().info(_("Specified lock has been successfully removed.")); - } - else //package name - { - //TODO localize - PoolQuery q; - q.addAttribute(sat::SolvAttr::name, args[0]); - q.setMatchGlob(); - //! \todo addRepo() - q.setCaseSensitive(); - - int res = 0; - PoolQuery& last = q; - for_( it, locks.begin(),locks.end() ) //if one package have identical name remove it directly + zypper.out().info(_("Specified lock has been successfully removed.")); + } + else //package name { - PoolQuery::StrContainer sc = it->attribute(sat::SolvAttr::name); - if (sc.size()==1 && sc.count(args[0]) ) + //TODO localize + //TODO fill query in one method to have consistent add/remove + //TODO what to do with repo and kinds? + PoolQuery q; + q.addAttribute(sat::SolvAttr::name, *args_it); + q.setMatchGlob(); + parsed_opts::const_iterator itr; + if ((itr = copts.find("repo")) != copts.end()) { - res++; - last = *it; + for_(it_repo,itr->second.begin(), itr->second.end()) + { + RepoInfo info; + if( match_repo( zypper, *it_repo, &info)) + q.addRepo(info.alias()); + else //TODO some error handling + WAR << "unknown repository" << *it_repo << endl; + } } - } - if ( res == 1 ) //only one exact name matching - locks.removeLock(last); - else - locks.removeLock(q); + q.setCaseSensitive(); - locks.save(); + //hack to remove unique lock added by zypper + int res = 0; + PoolQuery& last = q; + for_( it, locks.begin(),locks.end() ) + { + PoolQuery::StrContainer sc = it->attribute(sat::SolvAttr::name); + if (sc.size()==1 && sc.count(*args_it) ) + { + res++; + last = *it; + } + } - if (start==locks.size()) - { - zypper.out().info("No lock has been removed."); - // nothing removed - } else { - zypper.out().info(str::form("Lock count has been succesfully decreased by: %lu",start-locks.size())); - //removed something + if (res == 1) //only one with identical name, then remove it + locks.removeLock(last); + else + locks.removeLock(q); } } + + locks.save(); + + if (start==locks.size()) + { + zypper.out().info("No lock has been removed."); + // nothing removed + } else { + zypper.out().info(str::form("Lock count has been succesfully decreased by: %lu",start-locks.size())); + //removed something + } } catch(const Exception & e) { ZYPP_CAUGHT(e); - zypper.out().error(e, _("Problem adding the package lock:")); + zypper.out().error(e, _("Problem removing the package lock:")); zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP); } } diff --git a/src/zypper-misc.cc b/src/zypper-misc.cc index 8e4ee09..016841d 100644 --- a/src/zypper-misc.cc +++ b/src/zypper-misc.cc @@ -2584,8 +2584,8 @@ void solve_and_commit (Zypper & zypper) } } // install any pending source packages - if (!zypper.runtimeData().srcpkgs_to_install.empty()) - install_src_pkgs(zypper); +/* if (!zypper.runtimeData().srcpkgs_to_install.empty()) + install_src_pkgs(zypper);*/ } } // noting to do diff --git a/src/zypper.cc b/src/zypper.cc index 07922e5..482dded 100644 --- a/src/zypper.cc +++ b/src/zypper.cc @@ -3117,7 +3117,8 @@ void Zypper::doCommand() return; } // too many arguments - else if (_arguments.size() > 1) + //TODO rug compatibility +/* else if (_arguments.size() > 1) { // rug compatibility if (_gopts.is_rug_compatible) @@ -3129,7 +3130,7 @@ void Zypper::doCommand() setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS); return; } - } + }*/ ResKindSet kinds; if (copts.count("type")) @@ -3151,12 +3152,6 @@ void Zypper::doCommand() else kinds.insert(ResKind::package); - init_target(*this); - init_repos(*this); - if (exitCode() != ZYPPER_EXIT_OK) - return; - load_resolvables(*this); - add_locks(*this, _arguments, kinds); break; @@ -3175,13 +3170,9 @@ void Zypper::doCommand() return; } - if (_arguments.size() != 1) + if (_arguments.size() == 1) { - if (_arguments.empty()) - report_required_arg_missing(out(), _command_help); - else - report_too_many_arguments(_command_help); - + report_required_arg_missing(out(), _command_help); setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS); return; } -- 2.7.4