Skip to content

Commit

Permalink
Merge pull request #592 from yast/reposiory_name
Browse files Browse the repository at this point in the history
Repository names
  • Loading branch information
lslezak committed Nov 19, 2021
2 parents 9f6b0a8 + d84de77 commit b4ac1ac
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 2 deletions.
7 changes: 7 additions & 0 deletions package/yast2-packager.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Fri Nov 19 14:09:32 UTC 2021 - Ladislav Slezák <lslezak@suse.cz>

- Use consistent names for the Full medium repositories
(bsc#1191652)
- 4.3.25

-------------------------------------------------------------------
Thu Jun 17 15:47:33 UTC 2021 - Ladislav Slezák <lslezak@suse.cz>

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-packager.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-packager
Version: 4.3.24
Version: 4.3.25
Release: 0
Summary: YaST2 - Package Library
License: GPL-2.0-or-later
Expand Down
3 changes: 2 additions & 1 deletion src/include/packager/repositories_include.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def initialize_packager_repositories_include(_include_target)
Yast.import "SourceDialogs"
Yast.import "Report"
Yast.import "Progress"
Yast.import "Packages"

textdomain "packager"

Expand Down Expand Up @@ -364,7 +365,7 @@ def scan_products(_expanded_url, original_url)
url_path = URL.Parse(original_url)["path"]
p_elems = url_path.split("/")

fallback = _("Repository")
fallback = Packages.fallback_name

if p_elems.size > 1
url_path = Ops.get(
Expand Down
22 changes: 22 additions & 0 deletions src/modules/Packages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,20 @@ def Initialize_BaseInit(show_popup, base_url, log_url)
true
end

# Fallback repository name
# @return [String] translated name
def fallback_name
_("Repository")
end

# Is the repository name a fallback name?
# @param name [String] name of the repository
# @return [Boolean] true if it is a fallback name
def is_fallback_name?(name)
# to make the names unique a number might be appended at the end
name == fallback_name || name =~ /^#{Regexp.escape(fallback_name)}_\d+$/
end

# Adjusts repository name according to a first product found on the media.
#
# @param [Fixnum] src_id repository ID
Expand All @@ -1529,6 +1543,13 @@ def AdjustSourcePropertiesAccordingToProduct(src_id)
return nil
end

# change only the fallback name, otherwise the name already contains a product
repo_name = Pkg.SourceGeneralData(src_id)["raw_name"]
if !is_fallback_name?(repo_name)
log.info("Keeping repository name #{repo_name.inspect} unchanged")
return false
end

Builtins.y2milestone("Trying to get repository name from products")
all_products = Y2Packager::Resolvable.find(kind: :product)
new_name = nil
Expand All @@ -1550,6 +1571,7 @@ def AdjustSourcePropertiesAccordingToProduct(src_id)
sources_set = []
Builtins.foreach(sources_got) do |one_source|
if Ops.get_integer(one_source, "SrcId", -1) == src_id
log.info("Updating repository name from \"#{repo_name}\" to \"#{new_name}\"")
Ops.set(one_source, "raw_name", new_name)
end
sources_set = Builtins.add(sources_set, one_source)
Expand Down
79 changes: 79 additions & 0 deletions test/packages_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1867,4 +1867,83 @@ def expect_source_urls(mapping)
expect(subject.send(:check_missing_resolvables)).to eq(pattern: ["non-existing"])
end
end

describe "#AdjustSourcePropertiesAccordingToProduct" do
let(:repo_id) { 42 }
# shared part of the Pkg.SourceGeneralData response
let(:repo_partial_data) do
{
"alias" => "Basesystem-Module_15.3-0",
"autorefresh" => false,
"base_urls" => ["cd:///"],
"enabled" => true,
"is_update_repo" => false,
"keeppackages" => false,
"mirror_list" => "",
"priority" => 99,
"product_dir" => "/Module-Basesystem",
"raw_url" => "cd:///",
"service" => "",
"type" => "YUM",
"url" => "cd:///",
"valid_repo_signature" => true
}
end

before do
allow(Yast::Pkg).to receive(:SourceGeneralData).with(repo_id).and_return(repo_data)
allow(Yast::Pkg).to receive(:SourceEditSet)
end

context "the repository uses the fallback name" do
let(:repo_data) do
repo_partial_data.merge(
"name" => Yast::Packages.fallback_name,
"raw_name" => Yast::Packages.fallback_name
)
end

let(:product_name) { "SuperProduct!" }

it "changes the repository name to the product name" do
expect(Y2Packager::Resolvable).to receive(:find).with(kind: :product)
.and_return([double("product", source: repo_id, name: product_name)])
expect(Yast::Pkg).to receive(:SourceEditGet).and_return(
[
"SrcId" => repo_id,
"autorefresh" => false,
"enabled" => true,
"keeppackages" => false,
"name" => Yast::Packages.fallback_name,
"priority" => 99,
"raw_name" => Yast::Packages.fallback_name,
"service" => ""
]
)
expect(Yast::Pkg).to receive(:SourceEditSet) do |list|
expect(list.first["raw_name"]).to eq(product_name)
end

subject.AdjustSourcePropertiesAccordingToProduct(repo_id)
end
end

context "the repository uses a product name" do
let(:repo_data) do
repo_partial_data.merge(
"name" => "Basesystem-Module 15.3-0",
"raw_name" => "Basesystem-Module 15.3-0"
)
end

it "does not change the repository name" do
expect(Yast::Pkg).to_not receive(:SourceEditSet)
subject.AdjustSourcePropertiesAccordingToProduct(repo_id)
end

it "returns false" do
expect(subject.AdjustSourcePropertiesAccordingToProduct(repo_id)).to eq(false)
end
end
end
end

0 comments on commit b4ac1ac

Please sign in to comment.