Skip to content

Commit 1521423

Browse files
committed
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.
1 parent 5a929d0 commit 1521423

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

src/commands/repos/add.cc

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,23 @@ int AddRepoCmd::execute(Zypper &zypper, const std::vector<std::string> &position
8888
report_too_few_arguments( zypper.out(), help() );
8989
return( ZYPPER_EXIT_ERR_INVALID_ARGS );
9090
case 1:
91-
if( !isRepoFile( positionalArgs_r[0] ) )
91+
if( isRepoFile( positionalArgs_r[0] ) )
9292
{
93-
zypper.out().error(_("If only one argument is used, it must be a URI pointing to a .repo file."));
94-
ERR << "Not a repo file." << endl;
95-
zypper.out().info( help() );
96-
return ( ZYPPER_EXIT_ERR_INVALID_ARGS );
93+
add_repo_from_file( zypper, positionalArgs_r[0], _commonProperties, _repoProperties, _disableCheck );
94+
break;
95+
}
96+
else if ( positionalArgs_r[0].find("obs") == 0 ) {
97+
bool withFilename = true;
98+
Url url = make_obs_url( positionalArgs_r[0], zypper.config().obs_baseUrl, zypper.config().obs_platform, withFilename );
99+
add_repo_from_file( zypper, repo::RepoVariablesUrlReplacer()(url).asCompleteString(), _commonProperties, _repoProperties, _disableCheck );
100+
break;
97101
}
98102
else
99103
{
100-
add_repo_from_file( zypper, positionalArgs_r[0], _commonProperties, _repoProperties, _disableCheck );
101-
break;
104+
zypper.out().error(_("If only one argument is used, it must be a URI pointing to a .repo file or a OBS repository."));
105+
ERR << "Not a repo file." << endl;
106+
zypper.out().info( help() );
107+
return ( ZYPPER_EXIT_ERR_INVALID_ARGS );
102108
}
103109
case 2:
104110
Url url;

src/utils/misc.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ namespace
394394
} // namespace
395395
///////////////////////////////////////////////////////////////////
396396

397-
Url make_obs_url( const std::string & obsuri, const Url & base_url, const std::string & default_platform )
397+
Url make_obs_url( const std::string & obsuri, const Url & base_url, const std::string & default_platform , bool guessRepoFilename )
398398
{
399399
// obs-server ==> < base_url, default_platform >
400400
static std::map<std::string, std::pair<Url,std::string>> wellKnownServers({
@@ -476,6 +476,9 @@ Url make_obs_url( const std::string & obsuri, const Url & base_url, const std::s
476476
else
477477
path /= platform;
478478

479+
if ( guessRepoFilename )
480+
path /= what[1] + ".repo";
481+
479482
ret.setPathName( path.asString() );
480483

481484
return ret;

src/utils/misc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ Url make_url( const std::string & url_s );
123123
* Creates Url out of obs://project/platform URI with given base URL and default
124124
* platform (used in case the platform is not specified in the URI).
125125
*/
126-
Url make_obs_url( const std::string & obsuri, const Url & base_url, const std::string & default_platform );
126+
Url make_obs_url( const std::string & obsuri, const Url & base_url, const std::string & default_platform, bool guessRepoFilename = false );
127127

128128
/**
129129
* Returns <code>true</code> if the string \a s contains a substring starting

0 commit comments

Comments
 (0)