Skip to content

Commit

Permalink
Try to guess repo file name for a obs:// uri ( fixes #262 )
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bzeller committed Mar 5, 2019
1 parent 5a929d0 commit 81c7a85
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
20 changes: 13 additions & 7 deletions src/commands/repos/add.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,23 @@ int AddRepoCmd::execute(Zypper &zypper, const std::vector<std::string> &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;
Expand Down
5 changes: 4 additions & 1 deletion src/utils/misc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::pair<Url,std::string>> wellKnownServers({
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>true</code> if the string \a s contains a substring starting
Expand Down

0 comments on commit 81c7a85

Please sign in to comment.