Author: jkupec Date: Fri Nov 30 13:06:19 2007 New Revision: 7988 URL: http://svn.opensuse.org/viewcvs/zypp?rev=7988&view=rev Log: - catch target initialization exceptions - catch exceptions from the search command - ExitRequestException added Modified: trunk/zypper/src/zypper-misc.cc trunk/zypper/src/zypper-repos.cc trunk/zypper/src/zypper.cc trunk/zypper/src/zypper.h Modified: trunk/zypper/src/zypper-misc.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-misc.cc?rev=7988&r1=7987&r2=7988&view=diff ============================================================================== --- trunk/zypper/src/zypper-misc.cc (original) +++ trunk/zypper/src/zypper-misc.cc Fri Nov 30 13:06:19 2007 @@ -44,7 +44,24 @@ //! \todo do this so that it works in zypper shell if (!done) { cout_v << _("Initializing Target") << endl; - God->initializeTarget(zypper.globalOpts().root_dir); + + try + { + God->initializeTarget(zypper.globalOpts().root_dir); + } + catch (const Exception & e) + { + report_problem(e, + _("Target initialization failed:"), + geteuid() != 0 ? + _("Running 'zypper refresh' as root might resolve the problem."):"" + ); + + zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP); + throw ExitRequestException( + "Target initialization failed: " + e.msg()); + } + done = true; } } Modified: trunk/zypper/src/zypper-repos.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-repos.cc?rev=7988&r1=7987&r2=7988&view=diff ============================================================================== --- trunk/zypper/src/zypper-repos.cc (original) +++ trunk/zypper/src/zypper-repos.cc Fri Nov 30 13:06:19 2007 @@ -204,8 +204,14 @@ // --------------------------------------------------------------------------- +/** + * Fill gData.repositories with active repos (enabled or specified) and refresh + * if autorefresh is on. + */ static void do_init_repos(Zypper & zypper) { + MIL << "Going to initialize repositories." << endl; + // load gpg keys cond_init_target(zypper); RepoManager manager(zypper.globalOpts().rm_options); @@ -291,6 +297,48 @@ } } } + // even if refresh is not required, try to build the sqlite cache + // for the case of non-existing cache + else if (repo.enabled()) + { + // handle root user differently + if (geteuid() == 0) + { + if (build_cache(zypper, repo, false)) + { + cerr << format(_("Disabling repository '%s' because of the above error.")) + % repo.name() << endl; + ERR << format("Disabling repository '%s' because of the above error.") + % repo.name() << endl; + + it->setEnabled(false); + } + } + // non-root user + else + { + // if error is returned, it means zypp attempted to build the sqlite + // cache for the repo and failed because writing is not allowed for + // non-root Thus, just display refresh hint for non-root user. + if (build_cache(zypper, repo, false)) + { + cout << format(_( + "The cache database needs to be built for the '%s' repository." + " You can run 'zypper refresh' as root to do this.")) % repo.name() + << endl; + + string nonroot = + "We're running as non-root, skipping building of " + repo.name() + "cache"; + MIL << nonroot << endl; + cout_vv << nonroot << endl; + + cerr << format(_("Disabling repository '%s'.")) + % repo.name() << endl << endl; + ERR << "Disabling repository '" << repo.name() << "'" << endl; + it->setEnabled(false); + } + } + } } } Modified: trunk/zypper/src/zypper.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper.cc?rev=7988&r1=7987&r2=7988&view=diff ============================================================================== --- trunk/zypper/src/zypper.cc (original) +++ trunk/zypper/src/zypper.cc Fri Nov 30 13:06:19 2007 @@ -473,7 +473,12 @@ //cerr << _("User requested to abort.") << endl; cerr << ex.asUserString() << endl; } - catch (const Exception & ex) { + catch (const ExitRequestException & e) + { + cout_vv << "Caught exit request:" << endl << e.msg() << endl; + } + catch (const Exception & ex) + { ZYPP_CAUGHT(ex); cerr << _("Unexpected exception.") << endl; @@ -1617,23 +1622,33 @@ Table t; t.style(Ascii); - ZyppSearch search( God, options, _arguments ); - FillTable callback( t, search.installedCache(), search.getQueryInstancePtr(), search.options() ); - - search.doSearch( callback, callback ); - - if (t.empty()) - cout << _("No resolvables found.") << endl; - else { - cout << endl; - if (copts.count("sort-by-catalog") || copts.count("sort-by-repo")) - t.sort(1); - else - t.sort(3); // sort by name - cout << t; + try + { + ZyppSearch search( God, options, _arguments ); + FillTable callback( t, search.installedCache(), search.getQueryInstancePtr(), search.options() ); + + search.doSearch( callback, callback ); + + if (t.empty()) + cout << _("No resolvables found.") << endl; + else { + cout << endl; + if (copts.count("sort-by-catalog") || copts.count("sort-by-repo")) + t.sort(1); + else + t.sort(3); // sort by name + cout << t; + } + } + catch (const Exception & e) + { + report_problem(e, + _("Problem occurred initializing or executing the search query") + string(":"), + string(_("See the above message for a hint.")) + " " + + _("Running 'zypper refresh' as root might resolve the problem.")); + setExitCode(ZYPPER_EXIT_ERR_ZYPP); } - setExitCode(ZYPPER_EXIT_OK); return; } Modified: trunk/zypper/src/zypper.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper.h?rev=7988&r1=7987&r2=7988&view=diff ============================================================================== --- trunk/zypper/src/zypper.h (original) +++ trunk/zypper/src/zypper.h Fri Nov 30 13:06:19 2007 @@ -157,6 +157,17 @@ extern RuntimeData gData; extern std::ostream no_stream; +class ExitRequestException +{ +public: + ExitRequestException(const std::string & msg = "") : _msg(msg) {} + ~ExitRequestException() {} + + const std::string & msg() const { return _msg; } +private: + std::string _msg; +}; + #endif /*ZYPPER_H*/ // Local Variables: -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org