From 288de36ef0a7af62635053f35434a6e027374605 Mon Sep 17 00:00:00 2001 From: Jan Kupec Date: Wed, 1 Nov 2006 14:39:47 +0000 Subject: [PATCH] zypper refresh implemented --- doc/zypper.8 | 11 +++++++++++ src/zmart-sources.cc | 40 ++++++++++++++++++++++++++++++++++++++++ src/zmart-sources.h | 1 + src/zypper.cc | 25 ++++++++++++++++++++++++- 4 files changed, 76 insertions(+), 1 deletion(-) diff --git a/doc/zypper.8 b/doc/zypper.8 index 4d418ef..d739b2f 100644 --- a/doc/zypper.8 +++ b/doc/zypper.8 @@ -151,6 +151,12 @@ rug compatibility mode: if \fI-r\fR global option is set, zypper doesn't include .B service-rename (sr) Rename a service (installation source). +.TP +.B refresh (ref) +Refresh all installation sources found in system. +.IP +This means downloading resolvables' metadata from source media and storing it in local cache, typically under /var/lib/zypp/cache. + .SH "GLOBAL OPTIONS" .TP .I \-h, \-\-help @@ -171,6 +177,11 @@ Specifies table style to use. Table style is identified by an integer number. TO .I \-r, \-\-rug\-compatible Turns on rug compatibility. See compatibility notes next to affected commands. +.SH "FILES" +.TP +.B /var/lib/zypp/cache +Directory for storing metadata contained in installation sources. + .SH "NOTE" .LP Currently, zypper can be run only by user with root privileges. diff --git a/src/zmart-sources.cc b/src/zmart-sources.cc index f3f34db..e975495 100644 --- a/src/zmart-sources.cc +++ b/src/zmart-sources.cc @@ -429,6 +429,46 @@ void rename_source( const std::string& anystring, const std::string& newalias ) manager->store( "/", true /*metadata_cache*/ ); } +void refresh_sources() +{ + zypp::storage::PersistentStorage store; + std::list sources; + + try + { + store.init( "/" ); + sources = store.storedSources(); + } + catch ( const Exception &e ) + { + cerr << _("Error reading system sources: ") << e.msg() << std::endl; + exit(-1); + } + + for(std::list::const_iterator it = sources.begin(); + it != sources.end() ; ++it) + { + try + { + cout << _("Refreshing ") << it->alias() << endl << + "URI: " << it->url() << endl; + Source_Ref src = SourceFactory().createFrom( + it->type(), it->url(), it->path(), it->alias(), it->cacheDir(), + false, // base source + true); // autorefresh +// src.refresh(); + cout << "DONE" << endl << endl; + } + catch ( const zypp::Exception & ex ) + { + cerr << _("Error while refreshing the source: ") << ex.asString(); + // continuing with next source, however + } + } + + cout << _("All sytem sources have been refreshed.") << endl; +} + MediaWrapper::MediaWrapper (const string& filename_or_url) { try { // the interface cannot provide a "complete path" :-( diff --git a/src/zmart-sources.h b/src/zmart-sources.h index 6e3ab08..c5a34f5 100644 --- a/src/zmart-sources.h +++ b/src/zmart-sources.h @@ -21,6 +21,7 @@ void add_source_by_url( const zypp::Url &url, std::string alias ); void remove_source( const std::string& anystring ); void rename_source( const std::string& anystring, const std::string& newalias ); void list_system_sources(); +void refresh_sources(); //! download a copy of a remote file or just return the argument diff --git a/src/zypper.cc b/src/zypper.cc index f9e4a52..01a338b 100644 --- a/src/zypper.cc +++ b/src/zypper.cc @@ -241,6 +241,7 @@ int main(int argc, char **argv) "\tservice-add, sa\t\tAdd a new service\n" "\tservice-delete, sd\tDelete a service\n" "\tservice-rename, sr\tRename a service\n" + "\trefresh, ref\t\tRefresh all installation sources\n" "\tpatch-check, pchk\tCheck for patches\n" "\tpatches, pch\t\tList patches\n" "\tlist-updates, lu\tList updates\n" @@ -301,6 +302,16 @@ int main(int argc, char **argv) "\n" ; } + else if (command == "refresh" || command == "ref") { + static struct option refresh_options[] = { + {"help", no_argument, 0, 'h'} + }; + specific_options = refresh_options; + specific_help = _("zypper refresh\n" + "\n" + "Refresh all installation sources found in system.\n") + ; + } else if (command == "list-updates" || command == "lu") { static struct option remove_options[] = { {"type", required_argument, 0, 't'}, @@ -335,7 +346,7 @@ int main(int argc, char **argv) {"type", required_argument, 0, 't'}, {"sort-by-name", no_argument, 0, 0}, {"sort-by-catalog", no_argument, 0, 0}, - {"help", no_argument, 0, 0} + {"help", no_argument, 0, 'h'} }; specific_options = search_options; specific_help = @@ -574,6 +585,18 @@ int main(int argc, char **argv) return 0; } + // --------------------------( refresh )------------------------------------ + + if (command == "refresh" || command == "ref") { + if (help || copts.count("help")) { + cerr << specific_help; + return !help; + } + + refresh_sources(); + } + + ResObject::Kind kind; // --------------------------( remove/install )----------------------------- -- 2.7.4