From: Jan Kupec Date: Sat, 4 Aug 2007 17:03:22 +0000 (+0000) Subject: - zypper refresh now takes aliases or repo numbers that should be X-Git-Tag: BASE-SuSE-Linux-10_3-Branch~196 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=48833fb3360bb69d01494af10b41ab41afa2b94d;p=platform%2Fupstream%2Fzypper.git - zypper refresh now takes aliases or repo numbers that should be refreshed as arguments. - zypper repos output fixed to show proper repo numbers (#296779) --- diff --git a/doc/zypper.8 b/doc/zypper.8 index 7630d9f..42e33f4 100644 --- a/doc/zypper.8 +++ b/doc/zypper.8 @@ -270,10 +270,10 @@ Enable auto-refresh for the repository. Disable auto-refresh for the repository. .TP -.B refresh (ref) -Refresh all installation sources found in system. +.B refresh (ref) [alias|#] ... +Refresh repositories specified by their alias or number. If no repositories are specified, all enabled repositories will be refreshed. .IP -This means downloading resolvables' metadata from source media (if needed), storing it in local cache (typically under /var/lib/zypp/cache/raw directory) and preparsing the metadata into an sqlite database (/var/lib/zypp/cache/zypp.db). +Refreshing a repository means downloading metadata of resolvables from media (if needed), storing it in local cache (typically under /var/cache/zypp/raw/ directory) and preparsing the metadata into an sqlite database (/var/cache/zypp/zypp.db). .SH "GLOBAL OPTIONS" .TP diff --git a/src/zypper-sources.cc b/src/zypper-sources.cc index f5de01f..b146c87 100644 --- a/src/zypper-sources.cc +++ b/src/zypper-sources.cc @@ -3,6 +3,7 @@ #include "zypper-sources.h" #include "zypper-tabulator.h" +#include #include #include #include @@ -151,7 +152,7 @@ static void print_repo_list( const std::list &repos ) tbl << th; int i = 1; - + for (std::list::const_iterator it = repos.begin(); it != repos.end(); ++it) { @@ -183,6 +184,7 @@ static void print_repo_list( const std::list &repos ) } tbl << tr; + i++; } if (tbl.empty()) @@ -217,34 +219,104 @@ void list_repos() // ---------------------------------------------------------------------------- -void refresh_repos() +template +void safe_lexical_cast (Source s, Target &tr) { + try { + tr = boost::lexical_cast (s); + } + catch (boost::bad_lexical_cast &) { + } +} + +// ---------------------------------------------------------------------------- + +int refresh_repos(vector & arguments) { RepoManager manager; - gData.repos = manager.knownRepositories(); + list repos; + try + { + repos = manager.knownRepositories(); + } + catch ( const Exception &e ) + { + ZYPP_CAUGHT(e); + cerr << _("Error reading repositories:") << endl + << e.asUserString() << endl; + return ZYPPER_EXIT_ERR_ZYPP; + } - int error_count = 0; - int enabled_repo_count = gData.repos.size(); - for (std::list::iterator it = gData.repos.begin(); - it != gData.repos.end(); ++it) + unsigned error_count = 0; + unsigned enabled_repo_count = repos.size(); + unsigned repo_number = 0; + unsigned argc = arguments.size(); + for (std::list::iterator it = repos.begin(); + it != repos.end(); ++it) { RepoInfo repo(*it); + repo_number++; + + if (argc) + { + bool specified_found = false; + + // search for the repo alias among arguments + for (vector::iterator it = arguments.begin(); + it != arguments.end(); ++it) + if ((*it) == repo.alias()) + { + specified_found = true; + arguments.erase(it); + break; + } + + // search for the repo number among arguments + if (!specified_found) + for (vector::iterator it = arguments.begin(); + it != arguments.end(); ++it) + { + unsigned tmp = 0; + safe_lexical_cast (*it, tmp); + if (tmp == repo_number) + { + specified_found = true; + arguments.erase(it); + break; + } + } + + if (!specified_found) + { + DBG << repo.alias() << "(#" << repo_number << ") not specified," + << " skipping." << endl; + enabled_repo_count--; + continue; + } + } // skip disabled repos if (!repo.enabled()) { - cout_v << format(_("Skipping disabled repository '%s'")) % repo.alias() - << endl; + string msg = boost::str( + format(_("Skipping disabled repository '%s'")) % repo.alias()); + + if (argc) + cerr << msg << endl; + else + cout_v << msg << endl; + enabled_repo_count--; continue; } + // do the refresh try { - cout_n << _("Refreshing ") << it->alias() << endl; - manager.refreshMetadata(repo); //! \todo progress reporting + cout_n << format(_("Refreshing '%s'")) % it->alias() << endl; + manager.refreshMetadata(repo, RepoManager::RefreshIfNeeded); cout_v << _("Creating repository cache...") << endl; - manager.buildCache(repo); + manager.buildCache(repo, RepoManager::BuildIfNeeded); //cout_n << _("DONE") << endl << endl; } @@ -261,14 +333,42 @@ void refresh_repos() % repo.alias() << endl; error_count++; } + + } + + // the rest of arguments are those not found, complain to the user + bool show_hint = arguments.size(); + for (vector::iterator it = arguments.begin(); + it != arguments.end();) + { + cerr << format(_("Repository '%s' not found by its alias or number.")) % *it + << endl; + it = arguments.erase(it); } + if (show_hint) + cout_n << _("Use 'zypper repos' to get the list of defined repositories.") + << endl; - if (error_count == enabled_repo_count) + // print the result message + if (enabled_repo_count == 0) + { + if (argc) + cerr << _("Specified repositories are not enabled or defined."); + else + cerr << _("There are no enabled repositories defined."); + + cout_n << endl + << _("Use 'zypper addrepo' or 'zypper modifyrepo' commands to add or enable repositories.") + << endl; + } + else if (error_count == enabled_repo_count) cerr << _("Could not refresh the repositories because of errors.") << endl; else if (error_count) cerr << _("Some of the repositories have not been refreshed because of error.") << endl; + else if (argc) + cout << _("Specified repositories have been refreshed.") << endl; else - cout_n << _("All repositories have been refreshed.") << endl; + cout << _("All repositories have been refreshed.") << endl; } // ---------------------------------------------------------------------------- @@ -412,17 +512,6 @@ ostream& operator << (ostream& s, const vector& v) { // ---------------------------------------------------------------------------- -template -void safe_lexical_cast (Source s, Target &tr) { - try { - tr = boost::lexical_cast (s); - } - catch (boost::bad_lexical_cast &) { - } -} - -// ---------------------------------------------------------------------------- - static bool looks_like_url (const string& s) { static bool schemes_shown = false; diff --git a/src/zypper-sources.h b/src/zypper-sources.h index 1b0c3c7..2885eb2 100644 --- a/src/zypper-sources.h +++ b/src/zypper-sources.h @@ -22,7 +22,7 @@ void list_repos(); /** * Refresh all enabled repositories. */ -void refresh_repos(); +int refresh_repos(std::vector & arguments); /** diff --git a/src/zypper.cc b/src/zypper.cc index 59d8bb8..751f38c 100644 --- a/src/zypper.cc +++ b/src/zypper.cc @@ -421,9 +421,10 @@ int one_command(const ZypperCommand & command, int argc, char **argv) }; specific_options = refresh_options; specific_help = _( - "refresh\n" + "refresh (ref) [alias|#] ...\n" "\n" - "Refresh all defined and enabled repositories.\n" + "Refresh repositories specified by their alias or number." + " If none are specified, all enabled repositories will be refreshed.\n" "\n" "This command has no additional options.\n" ); @@ -964,7 +965,7 @@ int one_command(const ZypperCommand & command, int argc, char **argv) return ZYPPER_EXIT_ERR_PRIVILEGES; } - refresh_repos(); + refresh_repos(arguments); } // --------------------------( remove/install )-----------------------------