Author: jkupec Date: Tue Sep 25 17:47:07 2007 New Revision: 7373 URL: http://svn.opensuse.org/viewcvs/zypp?rev=7373&view=rev Log: - report malformed URLs correctly in zypper addrepo (#325660) Modified: trunk/zypper/src/zypper-sources.cc trunk/zypper/src/zypper-utils.cc trunk/zypper/src/zypper-utils.h trunk/zypper/src/zypper.cc Modified: trunk/zypper/src/zypper-sources.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-sources.cc?rev=7373&r1=7372&r2=7373&view=diff ============================================================================== --- trunk/zypper/src/zypper-sources.cc (original) +++ trunk/zypper/src/zypper-sources.cc Tue Sep 25 17:47:07 2007 @@ -661,7 +661,7 @@ int add_repo(RepoInfo & repo) { RepoManager manager; - + bool is_cd = true; for(RepoInfo::urls_const_iterator it = repo.baseUrlsBegin(); it != repo.baseUrlsEnd(); ++it) @@ -676,6 +676,7 @@ repo.setAutorefresh(false); } + MIL << "Going to add repository: " << repo << endl; try @@ -766,20 +767,23 @@ const string & type, tribool enabled, tribool autorefresh) { + MIL << "going to add repository by url (alias=" << alias << ", url=" << url + << ")" << endl; + RepoManager manager; RepoInfo repo; - + if ( ! type.empty() ) repo.setType(RepoType(type)); - + repo.setAlias(alias.empty() ? timestamp() : alias); repo.addBaseUrl(url); - + if ( !indeterminate(enabled) ) repo.setEnabled((enabled == true)); if ( !indeterminate(autorefresh) ) repo.setAutorefresh((autorefresh == true)); - + return add_repo(repo); } @@ -790,7 +794,10 @@ tribool enabled, tribool autorefresh) { //! \todo handle local .repo files, validate the URL - Url url(repo_file_url); + Url url = make_url(repo_file_url); + if (!url.isValid()) + return ZYPPER_EXIT_ERR_INVALID_ARGS; + RepoManager manager; list<RepoInfo> repos; Modified: trunk/zypper/src/zypper-utils.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-utils.cc?rev=7373&r1=7372&r2=7373&view=diff ============================================================================== --- trunk/zypper/src/zypper-utils.cc (original) +++ trunk/zypper/src/zypper-utils.cc Tue Sep 25 17:47:07 2007 @@ -52,9 +52,20 @@ bool is_changeable_media(const zypp::Url & url) { - media::MediaManager mm; media::MediaAccessId id = mm.open(url); - bool is_cd = mm.isChangeable(id); - mm.close(id); + bool is_cd = false; + try + { + media::MediaManager mm; + media::MediaAccessId id = mm.open(url); + is_cd = mm.isChangeable(id); + mm.close(id); + } + catch (const media::MediaException & e) + { + ZYPP_CAUGHT(e); + WAR << "Could not determine if the URL points to a changeable media" << endl; + } + return is_cd; } @@ -87,3 +98,19 @@ // default return _PL("resolvable", "resolvables", count); } + +// ---------------------------------------------------------------------------- + +Url make_url (const string & url_s) { + Url u; + + try { + u = Url( (url_s[0] == '/') ? string("dir:") + url_s : url_s ); + } + catch ( const Exception & excpt_r ) { + ZYPP_CAUGHT( excpt_r ); + cerr << _("Given URL is invalid.") << endl; + cerr << excpt_r.asUserString() << endl; + } + return u; +} Modified: trunk/zypper/src/zypper-utils.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-utils.h?rev=7373&r1=7372&r2=7373&view=diff ============================================================================== --- trunk/zypper/src/zypper-utils.h (original) +++ trunk/zypper/src/zypper-utils.h Tue Sep 25 17:47:07 2007 @@ -21,4 +21,10 @@ std::string kind_to_string_localized( const zypp::KindOfzypp::Resolvable & kind, unsigned long count); +/** + * Constructor wrapper catching exceptions, + * returning an empty one on error. + */ +zypp::Url make_url (const std::string & url_s); + #endif /*ZYPPER_UTILS_H*/ Modified: trunk/zypper/src/zypper.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper.cc?rev=7373&r1=7372&r2=7373&view=diff ============================================================================== --- trunk/zypper/src/zypper.cc (original) +++ trunk/zypper/src/zypper.cc Tue Sep 25 17:47:07 2007 @@ -61,24 +61,6 @@ DigestCallbacks digest_callbacks; -/** - * Constructor wrapper catching exceptions, - * returning an empty one on error. - */ -Url make_url (const string & url_s) { - Url u; - - try { - u = Url( (url_s[0] == '/') ? string("dir:") + url_s : url_s ); - } - catch ( const Exception & excpt_r ) { - ZYPP_CAUGHT( excpt_r ); - cerr << _("Given URL is invalid.") << endl; - cerr << excpt_r.asUserString() << endl; - } - return u; -} - bool ghelp = false; static string help_commands = _( " Commands:\n" @@ -848,28 +830,22 @@ cout_n << specific_help; return ZYPPER_EXIT_ERR_INVALID_ARGS; } - + Url url = make_url (arguments[0]); - if (!url.isValid()) //! \todo error message + if (!url.isValid()) return ZYPPER_EXIT_ERR_INVALID_ARGS; - - string alias; - if (arguments.size() > 1) - alias = arguments[1]; - //! \todo use timestamp as alias, if no alias was given? - if (alias.empty ()) - alias = url.asString(); - + // by default, enable the repo and set autorefresh if (indeterminate(enabled)) enabled = true; if (indeterminate(refresh)) refresh = true; - + warn_if_zmd(); - + // load gpg keys cond_init_target (); - - return add_repo_by_url(url, alias, type, enabled, refresh); + + return add_repo_by_url( + url, arguments[1]/*alias*/, type, enabled, refresh); } catch (const repo::RepoUnknownTypeException & e) { -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org