Skip to content

Commit a266a71

Browse files
committed
Add functionality to modifyrepo for changing the baseurl of a repository (bsc#991030)
1 parent 384f025 commit a266a71

File tree

5 files changed

+42
-12
lines changed

5 files changed

+42
-12
lines changed

src/commands/repos/modify.cc

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,19 @@ zypp::ZyppFlags::CommandGroup ModifyRepoCmd::cmdOptions() const
4444
{
4545
auto that = const_cast<ModifyRepoCmd *>(this);
4646
return {{
47+
{"baseurl", 'u', ZyppFlags::RequiredArgument, ZyppFlags::StringType( &that->_baseUrl, {}, ARG_URI ), _("Set a base URL for the repository.")},
4748
//some legacy options
4849
{"legacy-refresh", 'r', ZyppFlags::NoArgument | ZyppFlags::Hidden, ZyppFlags::TriBoolType( that->_commonProps._enableAutoRefresh, ZyppFlags::StoreTrue ), "" },
4950
{"legacy-no-refresh", 'R', ZyppFlags::NoArgument | ZyppFlags::Hidden, ZyppFlags::TriBoolType( that->_commonProps._enableAutoRefresh, ZyppFlags::StoreFalse), "" }
5051
}};
5152
}
5253

5354
void ModifyRepoCmd::doReset()
54-
{ }
55+
{
56+
_baseUrl = std::string();
57+
}
5558

56-
int ModifyRepoCmd::execute(Zypper &zypper, const std::vector<std::string> &positionalArgs_r )
59+
int ModifyRepoCmd::execute( Zypper &zypper, const std::vector<std::string> &positionalArgs_r )
5760
{
5861
bool aggregate = _selections._all || _selections._local || _selections._remote || _selections._mediumTypes.size();
5962

@@ -71,6 +74,15 @@ int ModifyRepoCmd::execute(Zypper &zypper, const std::vector<std::string> &posit
7174
return ( ZYPPER_EXIT_ERR_INVALID_ARGS );
7275
}
7376

77+
if ( aggregate && !_baseUrl.empty() )
78+
{
79+
// translators: aggregate option is e.g. "--all". This message will be
80+
// followed by mr command help text which will explain it
81+
zypper.out().error(_("It is not possible to use --baseurl with aggregate options."));
82+
zypper.out().info( help() );
83+
return ZYPPER_EXIT_ERR_INVALID_ARGS;
84+
}
85+
7486
if ( aggregate )
7587
{
7688
modify_repos_by_option( zypper, _selections, _commonProps, _repoProps );
@@ -82,7 +94,7 @@ int ModifyRepoCmd::execute(Zypper &zypper, const std::vector<std::string> &posit
8294
RepoInfo r;
8395
if ( match_repo(zypper,*arg,&r) )
8496
{
85-
modify_repo( zypper, r.alias(), _commonProps, _repoProps );
97+
modify_repo( zypper, r.alias(), _baseUrl, _commonProps, _repoProps );
8698
}
8799
else
88100
{
@@ -93,7 +105,7 @@ int ModifyRepoCmd::execute(Zypper &zypper, const std::vector<std::string> &posit
93105
}
94106
}
95107

96-
return ZYPPER_EXIT_OK;
108+
return zypper.exitCode();
97109
}
98110

99111

src/commands/repos/modify.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class ModifyRepoCmd : public ZypperBaseCommand
2828
RepoServiceCommonOptions _commonProps{OptCommandCtx::RepoContext, *this};
2929
RepoProperties _repoProps{*this};
3030
RepoServiceCommonSelectOptions _selections{OptCommandCtx::RepoContext, *this};
31+
std::string _baseUrl;
3132
};
3233

3334
#endif

src/commands/services/modify.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ int ModifyServiceCmd::execute(Zypper &zypper, const std::vector<std::string> &po
9696
else {
9797
RepoProperties rProps;
9898
rProps.reset();
99-
modify_repo( zypper, srv->alias(), _commonProperties, rProps );
99+
modify_repo( zypper, srv->alias(), std::string(), _commonProperties, rProps );
100100
}
101101
}
102102
else
@@ -314,7 +314,7 @@ void ModifyServiceCmd::modifyServicesByOption( Zypper & zypper )
314314
else {
315315
RepoProperties rProps;
316316
rProps.reset();
317-
modify_repo( zypper, (*it)->alias(), _commonProperties, rProps );
317+
modify_repo( zypper, (*it)->alias(), std::string(), _commonProperties, rProps );
318318
}
319319
}
320320
return;
@@ -369,5 +369,5 @@ void ModifyServiceCmd::modifyServicesByOption( Zypper & zypper )
369369
RepoProperties rProps;
370370
rProps.reset();
371371
for_( it, repos_to_modify.begin(), repos_to_modify.end() )
372-
modify_repo( zypper, *it, _commonProperties, rProps );
372+
modify_repo( zypper, *it, std::string(), _commonProperties, rProps );
373373
}

src/repos.cc

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,7 +1522,7 @@ void modify_repos_by_option( Zypper & zypper, const RepoServiceCommonSelectOptio
15221522
RepoInfoSet toModify = collect_repos_by_option( zypper, selectOpts );
15231523
for_( it, toModify.begin(), toModify.end() )
15241524
{
1525-
modify_repo( zypper, it->alias(), commonOpts, repoProps );
1525+
modify_repo( zypper, it->alias(), std::string(), commonOpts, repoProps );
15261526
}
15271527
}
15281528

@@ -1531,7 +1531,7 @@ void modify_repos_by_option( Zypper & zypper, const RepoServiceCommonSelectOptio
15311531

15321532

15331533

1534-
void modify_repo( Zypper & zypper, const std::string & alias, const RepoServiceCommonOptions &commonOpts, const RepoProperties &repoProps )
1534+
void modify_repo( Zypper & zypper, const std::string & alias, const std::string &newBaseUrl, const RepoServiceCommonOptions &commonOpts, const RepoProperties &repoProps )
15351535
{
15361536
// enable/disable repo
15371537
const TriBool &enable = commonOpts._enable;
@@ -1582,7 +1582,7 @@ void modify_repo( Zypper & zypper, const std::string & alias, const RepoServiceC
15821582
if ( gpgCheck != RepoInfo::GpgCheck::indeterminate )
15831583
{
15841584
if ( repo.setGpgCheck( gpgCheck ) )
1585-
changed_gpgcheck = true;
1585+
changed_gpgcheck = true;
15861586
}
15871587

15881588
if ( prio >= 1 )
@@ -1600,8 +1600,19 @@ void modify_repo( Zypper & zypper, const std::string & alias, const RepoServiceC
16001600
if ( !name.empty() )
16011601
repo.setName( name );
16021602

1603+
if ( !newBaseUrl.empty() )
1604+
{
1605+
Url url = make_url( newBaseUrl );
1606+
if ( !url.isValid() )
1607+
{
1608+
zypper.setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
1609+
return;
1610+
}
1611+
repo.setBaseUrl( url );
1612+
}
1613+
16031614
if ( changed_enabled || changed_autoref || changed_prio
1604-
|| changed_keeppackages || changed_gpgcheck || !name.empty() )
1615+
|| changed_keeppackages || changed_gpgcheck || !name.empty() || !newBaseUrl.empty() )
16051616
{
16061617
std::string volatileNote; // service repos changes may be volatile
16071618
std::string volatileNoteIfPlugin; // plugin service repos changes may be volatile
@@ -1665,6 +1676,12 @@ void modify_repo( Zypper & zypper, const std::string & alias, const RepoServiceC
16651676
zypper.out().info( str::Format(_("Name of repository '%s' has been set to '%s'.")) % alias % name, volatileNote );
16661677
}
16671678

1679+
if ( !newBaseUrl.empty() )
1680+
{
1681+
if ( !volatileNote.empty() ) didVolatileChanges = true;
1682+
zypper.out().info( str::Format(_("Baseurl of repository '%s' has been set to '%s'.")) % alias % newBaseUrl, volatileNote );
1683+
}
1684+
16681685
if ( didVolatileChanges )
16691686
{
16701687
zypper.out().warning( volatileServiceRepoChange( repo ) );

src/repos.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void remove_repos_by_option(Zypper & zypper_r , const RepoServiceCommonSelectOpt
174174
*
175175
* \param alias repository alias
176176
*/
177-
void modify_repo( Zypper & zypper, const std::string & alias, const RepoServiceCommonOptions &commonOpts, const RepoProperties &repoProps );
177+
void modify_repo( Zypper & zypper, const std::string & alias, const std::string &newBaseUrl, const RepoServiceCommonOptions &commonOpts, const RepoProperties &repoProps );
178178

179179
/**
180180
* Modify repositories which is matching filter options

0 commit comments

Comments
 (0)