Skip to content

Commit

Permalink
Add functionality to modifyrepo for changing the baseurl of a reposit…
Browse files Browse the repository at this point in the history
…ory (bsc#991030)
  • Loading branch information
bzeller committed May 15, 2018
1 parent 793b12a commit 643626c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/Zypper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2307,6 +2307,7 @@ void Zypper::processCommandOptions()
{
static struct option service_modify_options[] = {
{"help", no_argument, 0, 'h'},
{"baseurl", required_argument, 0, 'u'},
ARG_REPO_PROP,
/* LEGACY(ARG_REPO_PROP) prefers -f */ {"refresh", no_argument, 0, 'r'},
/* LEGACY(ARG_REPO_PROP) prefers -F */ {"no-refresh", no_argument, 0, 'R'},
Expand Down Expand Up @@ -2352,6 +2353,7 @@ void Zypper::processCommandOptions()
_("Modify properties of repositories specified by alias, number, or URI, or by the '%1%' aggregate options.") ) % "--all, --remote, --local, --medium-type"
)
.optionSectionCommandOptions()
.option( "-u, --baseurl <URI>", _("Set a base URL for the repository.") )
.option_REPO_PROP
.gap()
.option( "-a, --all", _("Apply changes to all repositories.") )
Expand Down Expand Up @@ -4107,6 +4109,16 @@ void Zypper::doCommand()
return;
}

if ( aggregate && copts.count("baseurl") )
{
// translators: aggregate option is e.g. "--all". This message will be
// followed by mr command help text which will explain it
out().error(_("It is not possible to use --baseurl with aggregate options."));
out().info( _command_help );
setExitCode( ZYPPER_EXIT_ERR_INVALID_ARGS );
return;
}

// too many arguments
if ( _arguments.size() && aggregate )
{
Expand Down
24 changes: 23 additions & 1 deletion src/repos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2148,8 +2148,24 @@ void modify_repo( Zypper & zypper, const std::string & alias )
repo.setName( name );
}

std::string baseurl;
if ( (tmp1 = zypper.cOpts().find("baseurl")) != zypper.cOpts().end() )
{
baseurl = *tmp1->second.begin();
if ( !baseurl.empty() )
{
Url url = make_url( baseurl );
if ( !url.isValid() )
{
zypper.setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
return;
}
repo.setBaseUrl( url );
}
}

if ( changed_enabled || changed_autoref || changed_prio
|| changed_keeppackages || changed_gpgcheck || !name.empty() )
|| changed_keeppackages || changed_gpgcheck || !name.empty() || !baseurl.empty() )
{
std::string volatileNote; // service repos changes may be volatile
std::string volatileNoteIfPlugin; // plugin service repos changes may be volatile
Expand Down Expand Up @@ -2213,6 +2229,12 @@ void modify_repo( Zypper & zypper, const std::string & alias )
zypper.out().info( str::Format(_("Name of repository '%s' has been set to '%s'.")) % alias % name, volatileNote );
}

if ( !baseurl.empty() )
{
if ( !volatileNote.empty() ) didVolatileChanges = true;
zypper.out().info( str::Format(_("Baseurl of repository '%s' has been set to '%s'.")) % alias % baseurl, volatileNote );
}

if ( didVolatileChanges )
{
zypper.out().warning( volatileServiceRepoChange( repo ) );
Expand Down

0 comments on commit 643626c

Please sign in to comment.