Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/SLE-15-SP1' into bsc1172477
Browse files Browse the repository at this point in the history
# Conflicts:
#	package/yast2-packager.changes
#	package/yast2-packager.spec
#	src/include/packager/repositories_include.rb
#	src/lib/packager/clients/repositories.rb
  • Loading branch information
aschnell committed Jul 15, 2020
2 parents 45eae79 + 61e81a9 commit e296d32
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 55 deletions.
6 changes: 6 additions & 0 deletions package/yast2-packager.changes
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Tue Jul 14 10:41:22 CEST 2020 - aschnell@suse.com

- Handle variable expansion in repository name (bsc#1172477)
- 4.2.64

-------------------------------------------------------------------
Fri Jul 10 07:14:05 UTC 2020 - Ladislav Slezák <lslezak@suse.cz>

Expand Down
10 changes: 5 additions & 5 deletions package/yast2-packager.spec
Expand Up @@ -17,7 +17,7 @@


Name: yast2-packager
Version: 4.2.63
Version: 4.2.64
Release: 0
Summary: YaST2 - Package Library
License: GPL-2.0-or-later
Expand All @@ -37,16 +37,16 @@ BuildRequires: yast2-storage-ng >= 4.0.141
#!BuildIgnore: yast2-packager
# Y2Packager::Repositories
BuildRequires: yast2 >= 4.2.60
# Pkg::Resolvables
BuildRequires: yast2-pkg-bindings >= 4.2.0
# raw_name
BuildRequires: yast2-pkg-bindings >= 4.2.8
# Augeas lenses
BuildRequires: augeas-lenses
BuildRequires: ruby-solv

# Newly added RPM
Requires: yast2-country-data >= 2.16.3
# Pkg::Resolvables
Requires: yast2-pkg-bindings >= 4.2.0
# raw_name
Requires: yast2-pkg-bindings >= 4.2.8
# Y2Packager::Repositories
Requires: yast2 >= 4.2.60
# unzipping license file
Expand Down
37 changes: 19 additions & 18 deletions src/include/packager/repositories_include.rb
Expand Up @@ -47,8 +47,8 @@ def LicenseAccepted(id)
# @param plaindir [Boolean] true to use "PlainDir" format (no repository
# metadata present at the URL)
# @param download [Boolean] whether to refresh the repository or not
# @param preffered_name [String] (optional) preferred repository name, use
# empty string "" to generate the name
# @param preferred_name [String] (optional) preferred repository raw_name, use
# empty string "" to generate the raw_name
# @param force_alias [String] alias for the new repository, if a repository
# with this alias already exists then it is overwritten, use empty string ""
# to generate an unique alias
Expand All @@ -62,9 +62,9 @@ def LicenseAccepted(id)
# TODO: abort is problematic as abort is used to abort installation, for license
# should be own symbol. Now abort in addon view in upgrade proposal ask for abort
# properly, but then just go back to proposal instead of full abort.
def createSourceImpl(url, plaindir, download, preffered_name, force_alias)
def createSourceImpl(url, plaindir, download, preferred_name, force_alias)
log.info("createSource: #{URL.HidePassword(url)}, plaindir: #{plaindir}," \
"download: #{download}, name: #{preffered_name}, force_alias: #{force_alias}")
"download: #{download}, preferred_name: #{preferred_name}, force_alias: #{force_alias}")

if url.nil? || url.empty?
Builtins.y2error(-1, "Empty URL! Backtrace:")
Expand Down Expand Up @@ -95,7 +95,7 @@ def createSourceImpl(url, plaindir, download, preffered_name, force_alias)
# create a new service if a service is detected at the URL
if ![nil, "NONE"].include?(service_type)
Builtins.y2milestone("Adding a service of type %1...", service_type)
add_service(url, preffered_name)
add_service(url, preferred_name)
return :ok
end

Expand Down Expand Up @@ -123,7 +123,7 @@ def createSourceImpl(url, plaindir, download, preffered_name, force_alias)
found_products.each do |product|
next if enter_again

name = (!preffered_name.nil? && preffered_name != "") ? preffered_name : product.name
name = (!preferred_name.nil? && preferred_name != "") ? preferred_name : product.name
# probe repository type (do not probe plaindir repo)
repo_type = plaindir ? PLAINDIR_TYPE : Pkg.RepositoryProbe(expanded_url, product.dir)
log.info("Repository type (#{URL.HidePassword(url)},#{product.dir}): #{repo_type}")
Expand All @@ -146,12 +146,12 @@ def createSourceImpl(url, plaindir, download, preffered_name, force_alias)
alias_name = (force_alias == "") ? propose_alias(product.name) : force_alias

# map with repository parameters: $[ "enabled" : boolean,
# "autorefresh" : boolean, "name" : string, "alias" : string,
# "autorefresh" : boolean, "raw_name" : string, "alias" : string,
# "base_urls" : list<string>, "prod_dir" : string, "type" : string ]
repo_prop = {
"enabled" => true,
"autorefresh" => autorefresh_for?(url),
"name" => name,
"raw_name" => name,
"prod_dir" => product.dir,
"alias" => alias_name,
"base_urls" => [url],
Expand Down Expand Up @@ -196,13 +196,14 @@ def createSourceImpl(url, plaindir, download, preffered_name, force_alias)
Pkg.SourceDelete(id)
else
src_data = Pkg.SourceGeneralData(id)
log.info("Addded repository: #{src_data}")
log.info("Added repository: #{src_data}")

sourceState = {
"SrcId" => id,
"enabled" => src_data["enabled"],
"autorefresh" => src_data["autorefresh"],
"name" => src_data["name"],
"raw_name" => src_data["raw_name"],
"do_refresh" => download
}
@sourceStatesOut << sourceState
Expand All @@ -212,20 +213,20 @@ def createSourceImpl(url, plaindir, download, preffered_name, force_alias)
:ok
end
ensure
# relese (unmount) the medium
# release (unmount) the medium
Pkg.SourceReleaseAll
end

# start createSource() function in extra wizard dialog
def createSource(url, plaindir, download, preffered_name)
createSourceWithAlias(url, plaindir, download, preffered_name, "")
def createSource(url, plaindir, download, preferred_name)
createSourceWithAlias(url, plaindir, download, preferred_name, "")
end

# create source with alias
# *IMPORTANT*: make sure the alias is unique!! Otherwise the repo will be overwritten!!
def createSourceWithAlias(url, plaindir, download, preffered_name, alias_name)
def createSourceWithAlias(url, plaindir, download, preferred_name, alias_name)
Wizard.CreateDialog
ret = createSourceImpl(url, plaindir, download, preffered_name, alias_name)
ret = createSourceImpl(url, plaindir, download, preferred_name, alias_name)
Wizard.CloseDialog
ret
end
Expand Down Expand Up @@ -440,8 +441,8 @@ def initialize_progress

# Add a new repository service.
# @param url [String] service URL
# @param preffered_name [String] service name, empty string means generate it
def add_service(url, preffered_name)
# @param preferred_name [String] service name, empty string means generate it
def add_service(url, preferred_name)
# all current aliases
aliases = @serviceStatesOut.map { |s| s["alias"] }

Expand All @@ -455,13 +456,13 @@ def add_service(url, preffered_name)
end

# use alias as the name if it's missing
preffered_name = alias_name if preffered_name.nil? || preffered_name == ""
preferred_name = alias_name if preferred_name.nil? || preferred_name == ""

new_service = {
"alias" => alias_name,
"autorefresh" => autorefresh_for?(url),
"enabled" => true,
"name" => preffered_name,
"raw_name" => preferred_name,
"url" => url
}

Expand Down
41 changes: 24 additions & 17 deletions src/lib/packager/clients/repositories.rb
Expand Up @@ -294,6 +294,7 @@ def getSourceInfo(_index, source)
"enabled" => Ops.get_boolean(source, "enabled", true),
"autorefresh" => Ops.get_boolean(source, "autorefresh", true),
"name" => Ops.get_locale(source, "name", _("Unknown Name")),
"raw_name" => source.fetch("raw_name", _("Unknown Name")),
"url" => Ops.get_string(generalData, "url", ""),
"raw_url" => Ops.get_string(generalData, "raw_url", ""),
"type" => Ops.get_string(generalData, "type", ""),
Expand Down Expand Up @@ -321,7 +322,7 @@ def fillTable(repo_mode, service_name)

itemList = repo_mode ? deep_copy(@sourceStatesOut) : deep_copy(@serviceStatesOut)

# displaye only repositories from the selected service
# display only repositories from the selected service
itemList = ReposFromService(service_name, itemList) if repo_mode && service_name != ""

numItems = Builtins.size(itemList)
Expand All @@ -343,6 +344,8 @@ def fillTable(repo_mode, service_name)
end

def repoInfoRichText(name, category, info)
raw_name = info["raw_name"]

url = info["url"]
raw_url = info["raw_url"]

Expand All @@ -352,6 +355,10 @@ def repoInfoRichText(name, category, info)
icon = ["cd", "dvd", "iso"].include?(schema) ? "yast-cd_update" : "yast-http-server"
icon_tag = "<IMG HEIGHT=\"22\" SRC=\"#{icon}\">&nbsp;&nbsp;&nbsp;"

# TRANSLATORS: the raw name is the original repository name with unexpanded variables
# like "$releasever"
name_string = (name != raw_name) ? _("Raw name: %s") % raw_name + "<BR>" : ""

url = _("Unknown") if url == ""
raw_url = _("Unknown") if raw_url == ""

Expand All @@ -364,9 +371,10 @@ def repoInfoRichText(name, category, info)
end

Builtins.sformat(
"<P>%1<B><BIG>%2</BIG></B></P><P>%3<BR>%4</P>",
"<P>%1<B><BIG>%2</BIG></B></P><P>%3%4<BR>%5</P>",
icon_tag,
name,
name_string,
url_string,
category
)
Expand Down Expand Up @@ -1783,7 +1791,8 @@ def repo_replace_handler(source_state, global_current)
old_url = url2
plaindir = Ops.get_string(generalData, "type", "YaST") == @plaindir_type

SourceDialogs.SetRepoName(Ops.get_string(source_state, "name", ""))
SourceDialogs.SetRepoName(source_state.fetch("raw_name", ""))

begin
url2 = SourceDialogs.EditPopupType(url2, plaindir)

Expand Down Expand Up @@ -1901,12 +1910,11 @@ def repo_replace_handler(source_state, global_current)
# remove the duplicate at the end
@sourceStatesOut = Builtins.remove(@sourceStatesOut, idx)

new_raw_name = addedSource.fetch("raw_name", "")
new_name = Yast::Pkg.ExpandedName(new_raw_name)

# refresh only the name and URL in the table
UI.ChangeWidget(
Id(:table),
Cell(global_current, 3),
Ops.get_string(addedSource, "name", "")
)
UI.ChangeWidget(Id(:table), Cell(global_current, 3), new_name)
UI.ChangeWidget(Id(:table), Cell(global_current, 5), url2)

fillCurrentRepoInfo
Expand All @@ -1917,19 +1925,18 @@ def repo_replace_handler(source_state, global_current)
"URL is the same, not recreating the source"
)

new_name = SourceDialogs.GetRepoName
if new_name != Ops.get_string(source_state, "name", "")
new_raw_name = SourceDialogs.GetRepoName
if new_raw_name != source_state.fetch("raw_name", "")
warn_service_repository(source_state)

Ops.set(source_state, "name", new_name)
Ops.set(@sourceStatesOut, global_current, source_state)
new_name = Yast::Pkg.ExpandedName(new_raw_name)

source_state["name"] = new_name
source_state["raw_name"] = new_raw_name
@sourceStatesOut[global_current] = source_state

# update only the name cell in the table
UI.ChangeWidget(
Id(:table),
Cell(global_current, 3),
new_name
)
UI.ChangeWidget(Id(:table), Cell(global_current, 3), new_name)

fillCurrentRepoInfo
else
Expand Down
2 changes: 1 addition & 1 deletion src/modules/SourceDialogs.rb
Expand Up @@ -7,7 +7,7 @@

# Yast namespace
module Yast
# Displays possibilities to install from NFS, CD or partion
# Displays possibilities to install from NFS, CD or partition
class SourceDialogsClass < Module
# to use N_ in the class constant
extend Yast::I18n
Expand Down
28 changes: 14 additions & 14 deletions test/repositories_include_test.rb
Expand Up @@ -47,7 +47,7 @@ def main
let(:url) { "cd://" }
let(:plaindir) { false }
let(:download) { false }
let(:preffered_name) { "" }
let(:preferred_name) { "" }
let(:repo_id) { 42 }

before do
Expand All @@ -70,7 +70,7 @@ def main
end

it "returns :again symbol when URL is empty" do
ret = RepositoryIncludeTester.createSource("", plaindir, download, preffered_name)
ret = RepositoryIncludeTester.createSource("", plaindir, download, preferred_name)
expect(ret).to eq(:again)
end

Expand All @@ -81,13 +81,13 @@ def main
end

it "returns :again symbol" do
ret = RepositoryIncludeTester.createSource(url, plaindir, download, preffered_name)
ret = RepositoryIncludeTester.createSource(url, plaindir, download, preferred_name)
expect(ret).to eq(:again)
end

it "displays an error popup" do
expect(Yast::Report).to receive(:Error).with(/Invalid URL/)
RepositoryIncludeTester.createSource(url, plaindir, download, preffered_name)
RepositoryIncludeTester.createSource(url, plaindir, download, preferred_name)
end
end

Expand All @@ -102,7 +102,7 @@ def main
end

it "returns :again symbol" do
result = RepositoryIncludeTester.createSource(url, plaindir, download, preffered_name)
result = RepositoryIncludeTester.createSource(url, plaindir, download, preferred_name)

expect(result).to eq(:again)
end
Expand All @@ -114,7 +114,7 @@ def main
end

it "returns :next symbol" do
result = RepositoryIncludeTester.createSource(url, plaindir, download, preffered_name)
result = RepositoryIncludeTester.createSource(url, plaindir, download, preferred_name)

expect(result).to eq(:next)
end
Expand All @@ -124,7 +124,7 @@ def main
it "creates the repository" do
repo_props = { "enabled" => true,
"autorefresh" => false,
"name" => "Repository",
"raw_name" => "Repository",
"prod_dir" => "/",
"alias" => "Repository",
"base_urls" => ["cd://"],
Expand All @@ -133,11 +133,11 @@ def main
expect(Yast::Pkg).to receive(:RepositoryAdd).with(repo_props).and_return(repo_id)
expect(Yast::Pkg).to_not receive(:SourceDelete)

RepositoryIncludeTester.createSource(url, plaindir, download, preffered_name)
RepositoryIncludeTester.createSource(url, plaindir, download, preferred_name)
end

it "returns :ok symbol on success" do
ret = RepositoryIncludeTester.createSource(url, plaindir, download, preffered_name)
ret = RepositoryIncludeTester.createSource(url, plaindir, download, preferred_name)
expect(ret).to eq(:ok)
end

Expand All @@ -146,7 +146,7 @@ def main
.with(repo_id).and_return(false)
expect(Yast::Pkg).to receive(:SourceDelete).with(repo_id)

RepositoryIncludeTester.createSource(url, plaindir, download, preffered_name)
RepositoryIncludeTester.createSource(url, plaindir, download, preferred_name)
end

context "more products available on the medium" do
Expand All @@ -170,7 +170,7 @@ def main

it "displays a dialog for selecting the products to use" do
expect_any_instance_of(Y2Packager::Dialogs::AddonSelector).to receive(:run)
RepositoryIncludeTester.createSource(url, plaindir, download, preffered_name)
RepositoryIncludeTester.createSource(url, plaindir, download, preferred_name)
end

it "adds only the repositories for the selected products" do
Expand All @@ -180,22 +180,22 @@ def main
.and_return(selected_products)
expect(Yast::Pkg).to receive(:RepositoryAdd)
.with(hash_including("prod_dir" => product1[1]))
RepositoryIncludeTester.createSource(url, plaindir, download, preffered_name)
RepositoryIncludeTester.createSource(url, plaindir, download, preferred_name)
end

it "returns :next if nothing is selected" do
expect_any_instance_of(Y2Packager::Dialogs::AddonSelector).to receive(:selected_products)
.and_return([])
expect_any_instance_of(Y2Packager::Dialogs::AddonSelector).to receive(:run)
.and_return(:next)
ret = RepositoryIncludeTester.createSource(url, plaindir, download, preffered_name)
ret = RepositoryIncludeTester.createSource(url, plaindir, download, preferred_name)
expect(ret).to eq(:next)
end

it "returns :abort if product selection is aborted" do
expect_any_instance_of(Y2Packager::Dialogs::AddonSelector).to receive(:run)
.and_return(:abort)
ret = RepositoryIncludeTester.createSource(url, plaindir, download, preffered_name)
ret = RepositoryIncludeTester.createSource(url, plaindir, download, preferred_name)
expect(ret).to eq(:abort)
end
end
Expand Down

0 comments on commit e296d32

Please sign in to comment.