From 1521423c64b010694752c86abe7e68063c8b3b38 Mon Sep 17 00:00:00 2001 From: Benjamin Zeller Date: Tue, 5 Mar 2019 14:32:23 +0100 Subject: [PATCH] Try to guess repo file name for a obs:// uri ( fixes #262 ) This enables zypper to automatically derive a .repo filename from an obs:// style url, adding some more convenience when dealing with those type of repositories. --- src/commands/repos/add.cc | 20 +++++++++++++------- src/utils/misc.cc | 5 ++++- src/utils/misc.h | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/commands/repos/add.cc b/src/commands/repos/add.cc index dbe7dad6d2..d3bcbcadff 100644 --- a/src/commands/repos/add.cc +++ b/src/commands/repos/add.cc @@ -88,17 +88,23 @@ int AddRepoCmd::execute(Zypper &zypper, const std::vector &position report_too_few_arguments( zypper.out(), help() ); return( ZYPPER_EXIT_ERR_INVALID_ARGS ); case 1: - if( !isRepoFile( positionalArgs_r[0] ) ) + if( isRepoFile( positionalArgs_r[0] ) ) { - zypper.out().error(_("If only one argument is used, it must be a URI pointing to a .repo file.")); - ERR << "Not a repo file." << endl; - zypper.out().info( help() ); - return ( ZYPPER_EXIT_ERR_INVALID_ARGS ); + add_repo_from_file( zypper, positionalArgs_r[0], _commonProperties, _repoProperties, _disableCheck ); + break; + } + else if ( positionalArgs_r[0].find("obs") == 0 ) { + bool withFilename = true; + Url url = make_obs_url( positionalArgs_r[0], zypper.config().obs_baseUrl, zypper.config().obs_platform, withFilename ); + add_repo_from_file( zypper, repo::RepoVariablesUrlReplacer()(url).asCompleteString(), _commonProperties, _repoProperties, _disableCheck ); + break; } else { - add_repo_from_file( zypper, positionalArgs_r[0], _commonProperties, _repoProperties, _disableCheck ); - break; + zypper.out().error(_("If only one argument is used, it must be a URI pointing to a .repo file or a OBS repository.")); + ERR << "Not a repo file." << endl; + zypper.out().info( help() ); + return ( ZYPPER_EXIT_ERR_INVALID_ARGS ); } case 2: Url url; diff --git a/src/utils/misc.cc b/src/utils/misc.cc index 2ac643c745..dc445e82b0 100644 --- a/src/utils/misc.cc +++ b/src/utils/misc.cc @@ -394,7 +394,7 @@ namespace } // namespace /////////////////////////////////////////////////////////////////// -Url make_obs_url( const std::string & obsuri, const Url & base_url, const std::string & default_platform ) +Url make_obs_url( const std::string & obsuri, const Url & base_url, const std::string & default_platform , bool guessRepoFilename ) { // obs-server ==> < base_url, default_platform > static std::map> wellKnownServers({ @@ -476,6 +476,9 @@ Url make_obs_url( const std::string & obsuri, const Url & base_url, const std::s else path /= platform; + if ( guessRepoFilename ) + path /= what[1] + ".repo"; + ret.setPathName( path.asString() ); return ret; diff --git a/src/utils/misc.h b/src/utils/misc.h index 9c4d990abf..ab6f91ed3c 100644 --- a/src/utils/misc.h +++ b/src/utils/misc.h @@ -123,7 +123,7 @@ Url make_url( const std::string & url_s ); * Creates Url out of obs://project/platform URI with given base URL and default * platform (used in case the platform is not specified in the URI). */ -Url make_obs_url( const std::string & obsuri, const Url & base_url, const std::string & default_platform ); +Url make_obs_url( const std::string & obsuri, const Url & base_url, const std::string & default_platform, bool guessRepoFilename = false ); /** * Returns true if the string \a s contains a substring starting