From 58c26331c91dc4d82629984b6c8c087bcdd85295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Mon, 27 Jul 2020 18:24:43 +0200 Subject: [PATCH 1/6] Display a warning for old packages --- src/data/old_packages/sle15_sp1.yml | 17 ++++ src/lib/installation/clients/inst_doit.rb | 5 ++ src/lib/installation/old_package.rb | 92 +++++++++++++++++++ src/lib/installation/old_package_check.rb | 28 ++++++ src/lib/installation/old_package_report.rb | 61 +++++++++++++ test/data/old_packages/sle15_sp1_test.yml | 17 ++++ test/old_package_report_test.rb | 100 +++++++++++++++++++++ test/old_package_test.rb | 55 ++++++++++++ 8 files changed, 375 insertions(+) create mode 100644 src/data/old_packages/sle15_sp1.yml create mode 100644 src/lib/installation/old_package.rb create mode 100644 src/lib/installation/old_package_check.rb create mode 100644 src/lib/installation/old_package_report.rb create mode 100644 test/data/old_packages/sle15_sp1_test.yml create mode 100644 test/old_package_report_test.rb create mode 100644 test/old_package_test.rb diff --git a/src/data/old_packages/sle15_sp1.yml b/src/data/old_packages/sle15_sp1.yml new file mode 100644 index 000000000..a54373068 --- /dev/null +++ b/src/data/old_packages/sle15_sp1.yml @@ -0,0 +1,17 @@ +packages: + - name: yast2 + version: 4.1.77-1.1 + arch: x86_64 + - name: yast2 + version: 4.1.77-1.1 + arch: aarch64 + + - name: yast2-pkg-bindings + version: 4.1.2-3.5.9 + arch: x86_64 + - name: yast2-pkg-bindings + version: 4.1.2-3.5.9 + arch: aarch64 + +message: | + These packages are too old, newer packages should be preferred. \ No newline at end of file diff --git a/src/lib/installation/clients/inst_doit.rb b/src/lib/installation/clients/inst_doit.rb index d892bb603..12085ba5d 100644 --- a/src/lib/installation/clients/inst_doit.rb +++ b/src/lib/installation/clients/inst_doit.rb @@ -19,6 +19,8 @@ # current contact information at www.novell.com. # ------------------------------------------------------------------------------ +require "installation/old_package_check" + module Yast # Asks user to really do the installation/update. class InstDoitClient < Client @@ -41,6 +43,9 @@ def main # bugzilla #256627 PackagesUI.ConfirmLicenses + # warn about installing old packages + ::Installation::OldPackageCheck.run + # function in installation/misc.ycp # bugzilla #219097 @confirmed = confirmInstallation diff --git a/src/lib/installation/old_package.rb b/src/lib/installation/old_package.rb new file mode 100644 index 000000000..09d424b7b --- /dev/null +++ b/src/lib/installation/old_package.rb @@ -0,0 +1,92 @@ +# ------------------------------------------------------------------------------ +# Copyright (c) 2020 SUSE LLC, All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of version 2 of the GNU General Public License as published by the +# Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# ------------------------------------------------------------------------------ + +require "yaml" +require "yast" + +## not present in SP1 :-( +## require "y2packager/resolvable" + +Yast.import "Pkg" +Yast.import "Report" + +module Installation + # This class represents an old package which should not be installed by users. + class OldPackage + include Yast::Logger + + attr_reader :name, :version, :arch, :message + + def initialize(name:, version:, arch:, message:) + @name = name + @version = version + @arch = arch + @message = message + end + + # @return [Y2Packager::Resolvable,nil] The selected old package or nil. + def selected_old + ## cannot be used in SP1, was added in SP2 + ## selected_packages = Resolvable.find(kind: :package, status: :selected, name: name, arch: arch) + packages = Yast::Pkg.ResolvableProperties(name, :package, "") + + # 1 = the selected is newer, the opposite is older or the same + packages.find do |p| + p["status"] == :selected && p["arch"] == arch && + Yast::Pkg.CompareVersions(version, p["version"]) == 1 + end + end + + # Reads the old package configuration files and creates the respective + # OldPackage objects. + def self.read(paths = nil) + # unfortunately we cannot use Yast::Directory.find_data_file + # here because it needs an exact file name, it does not accept a glob, + # use Yast.y2paths to honor the Y2DIR setting + data_paths = paths || Yast.y2paths.map { |p| File.join(p, "data", "old_packages") } + data_paths.select { |p| File.directory?(p) } + + log.debug "Found data directories: #{data_paths.inspect}" + + data_files = data_paths.each_with_object([]) do |p, obj| + # find all *.yml and *.yaml files + obj.concat(Dir[File.join(p, "*.y{a,}ml")]) + end + + log.debug "Found data files: #{data_files.inspect}" + + # remove the duplicates, this ensures the Y2DIR precedence + data_files.uniq! do |f| + File.basename(f) + end + + log.debug "Unique data files: #{data_files.inspect}" + + data_files.each_with_object([]) do |f, arr| + log.info "Loading file #{f.inspect}" + + config = YAML.load_file(f) + message = config["message"] || "" + packages = config["packages"] || [] + + packages.each do |p| + arr << new( + name: p["name"], + version: p["version"], + arch: p["arch"], + message: message + ) + end + end + end + end +end diff --git a/src/lib/installation/old_package_check.rb b/src/lib/installation/old_package_check.rb new file mode 100644 index 000000000..dedf51128 --- /dev/null +++ b/src/lib/installation/old_package_check.rb @@ -0,0 +1,28 @@ +# ------------------------------------------------------------------------------ +# Copyright (c) 2020 SUSE LLC, All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of version 2 of the GNU General Public License as published by the +# Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# ------------------------------------------------------------------------------ + +require "yast" + +require "installation/old_package_report" +require "installation/old_package" + +module Installation + # This class checks whether some old packages are selected + # and displays a warning to the user. + class OldPackageCheck + def self.run + old_packages = OldPackage.read + reporter = OldPackageReport.new(old_packages) + reporter.report + end + end +end diff --git a/src/lib/installation/old_package_report.rb b/src/lib/installation/old_package_report.rb new file mode 100644 index 000000000..10d67dfe0 --- /dev/null +++ b/src/lib/installation/old_package_report.rb @@ -0,0 +1,61 @@ +# ------------------------------------------------------------------------------ +# Copyright (c) 2020 SUSE LLC, All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of version 2 of the GNU General Public License as published by the +# Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# ------------------------------------------------------------------------------ + +require "yast" + +Yast.import "Report" +Yast.import "HTML" + +module Installation + # This class checks whether some old packages are selected + # and displays a warning to the user. + class OldPackageReport + include Yast::Logger + include Yast::I18n + + attr_reader :old_packages + + def initialize(old_packages) + textdomain "installation" + @old_packages = old_packages + end + + def report + report_packages = old_packages.select(&:selected_old) + if report_packages.empty? + log.info "No old package selected" + return + end + + log.warn("Detected old packages in the package selection: #{report_packages.inspect}") + + grouped_packages = report_packages.group_by(&:message) + + pkg_summary = grouped_packages.each_with_object("") do |(msg, pkgs), str| + package_names = pkgs.map do |pkg| + old = pkg.selected_old + "#{old["name"]}-#{old["version"]}-#{old["arch"]}" + end + + str << "

" + str << Yast::HTML.List(package_names) + str << msg + str << "


" + end + + message = format(_("The installer detected old package versions selected " \ + "for installation: \n\n%{list}"), list: pkg_summary) + + Yast::Report.LongWarning(message) + end + end +end diff --git a/test/data/old_packages/sle15_sp1_test.yml b/test/data/old_packages/sle15_sp1_test.yml new file mode 100644 index 000000000..566f886a1 --- /dev/null +++ b/test/data/old_packages/sle15_sp1_test.yml @@ -0,0 +1,17 @@ +packages: + - name: yast2 + version: 4.1.77-1.1 + arch: x86_64 + - name: yast2 + version: 4.1.77-1.1 + arch: aarch64 + + - name: yast2-pkg-bindings + version: 4.1.2-3.5.9 + arch: x86_64 + - name: yast2-pkg-bindings + version: 4.1.2-3.5.9 + arch: aarch64 + +message: | + These packages are too old, newer packages should be preferred. diff --git a/test/old_package_report_test.rb b/test/old_package_report_test.rb new file mode 100644 index 000000000..daa98471c --- /dev/null +++ b/test/old_package_report_test.rb @@ -0,0 +1,100 @@ +#! /usr/bin/env rspec + +require_relative "test_helper" + +require "installation/old_package" +require "installation/old_package_report" + +describe Installation::OldPackageReport do + let(:message1) { "These packages are too old, install new ones." } + let(:message2) { "This package contains a bug." } + let(:old_package1) do + Installation::OldPackage.new( + name: "yast2", + version: "4.1.77-1.1", + arch: "x86_64", + message: message1 + ) + end + let(:old_package2) do + Installation::OldPackage.new( + name: "yast2-pkg-bindings", + version: "4.1.2-3.5.9", + arch: "x86_64", + message: message2 + ) + end + + subject { Installation::OldPackageReport.new([old_package1, old_package2]) } + + describe "#report" do + before do + expect(old_package1).to receive(:selected_old).at_least(:once) + .and_return(selected_package1) + expect(old_package2).to receive(:selected_old).at_least(:once) + .and_return(selected_package2) + end + + context "No old package selected" do + let(:selected_package1) { nil } + let(:selected_package2) { nil } + + it "does not report any error" do + expect(Yast::Report).to_not receive(:LongWarning) + subject.report + end + end + + context "An old package is selected" do + let(:selected_package1) do + Y2Packager::Resolvable.new( + "name" => "yast2", + "version" => "4.1.77-1.1", + "arch" => "x86_64" + ) + end + let(:selected_package2) { nil } + + it "reports an error" do + expect(Yast::Report).to receive(:LongWarning).with(/#{message1}/) + subject.report + end + end + + context "More old packages are selected" do + let(:selected_package1) do + Y2Packager::Resolvable.new( + "name" => "yast2", + "version" => "4.1.77-1.1", + "arch" => "x86_64" + ) + end + let(:selected_package2) do + Y2Packager::Resolvable.new( + "name" => "yast2-pkg-bindings", + "version" => "4.1.2-3.5.9", + "arch" => "x86_64" + ) + end + + it "reports an error for all packages" do + expect(Yast::Report).to receive(:LongWarning) do |message| + expect(message).to include(message1) + expect(message).to include(message2) + end + + subject.report + end + + it "groups the packages with the same message" do + allow(old_package2).to receive(:message).and_return(message1) + + expect(Yast::Report).to receive(:LongWarning) do |message| + expect(message.scan(message1).size).to eq(1) + end + + subject.report + end + end + end +end diff --git a/test/old_package_test.rb b/test/old_package_test.rb new file mode 100644 index 000000000..e5b4b8bc9 --- /dev/null +++ b/test/old_package_test.rb @@ -0,0 +1,55 @@ +#! /usr/bin/env rspec + +require_relative "test_helper" + +require "installation/old_package" + +data_path = File.join(__dir__, "data", "old_packages") + +describe Installation::OldPackage do + describe ".read" do + it "reads the data files" do + pkgs = Installation::OldPackage.read([data_path]) + expect(pkgs.size).to eq(4) + pkgs.each { |p| expect(p).to be_a(Installation::OldPackage) } + end + end + + describe "#selected_old" do + subject { Installation::OldPackage.read([data_path]).first } + + context "no package is selected" do + before do + expect(Y2Packager::Resolvable).to receive(:find).and_return([]) + end + + it "returns nil" do + expect(subject.selected_old).to be_nil + end + end + + context "an old package is selected" do + let(:old_package) { Y2Packager::Resolvable.new("name" => "yast2", "version" => "4.1.69-1.2") } + + before do + expect(Y2Packager::Resolvable).to receive(:find).and_return([old_package]) + end + + it "returns the old package Resolvable" do + expect(subject.selected_old).to be(old_package) + end + end + + context "a new package is selected" do + let(:new_package) { Y2Packager::Resolvable.new("name" => "yast2", "version" => "4.1.99-1.2") } + + before do + expect(Y2Packager::Resolvable).to receive(:find).and_return([new_package]) + end + + it "returns nil" do + expect(subject.selected_old).to be_nil + end + end + end +end From f5ea679246ca7710e486bf83a5db7ea6d15a3806 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Tue, 28 Jul 2020 10:38:54 +0200 Subject: [PATCH 2/6] Adapt to the old SP1 code --- src/lib/installation/old_package.rb | 7 +------ test/old_package_report_test.rb | 12 ++++++------ test/old_package_test.rb | 16 ++++++++++------ 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/lib/installation/old_package.rb b/src/lib/installation/old_package.rb index 09d424b7b..30923e446 100644 --- a/src/lib/installation/old_package.rb +++ b/src/lib/installation/old_package.rb @@ -13,9 +13,6 @@ require "yaml" require "yast" -## not present in SP1 :-( -## require "y2packager/resolvable" - Yast.import "Pkg" Yast.import "Report" @@ -33,10 +30,8 @@ def initialize(name:, version:, arch:, message:) @message = message end - # @return [Y2Packager::Resolvable,nil] The selected old package or nil. + # @return [Hash,nil] The selected old package or nil. def selected_old - ## cannot be used in SP1, was added in SP2 - ## selected_packages = Resolvable.find(kind: :package, status: :selected, name: name, arch: arch) packages = Yast::Pkg.ResolvableProperties(name, :package, "") # 1 = the selected is newer, the opposite is older or the same diff --git a/test/old_package_report_test.rb b/test/old_package_report_test.rb index daa98471c..8ffd250ce 100644 --- a/test/old_package_report_test.rb +++ b/test/old_package_report_test.rb @@ -47,11 +47,11 @@ context "An old package is selected" do let(:selected_package1) do - Y2Packager::Resolvable.new( + { "name" => "yast2", "version" => "4.1.77-1.1", "arch" => "x86_64" - ) + } end let(:selected_package2) { nil } @@ -63,18 +63,18 @@ context "More old packages are selected" do let(:selected_package1) do - Y2Packager::Resolvable.new( + { "name" => "yast2", "version" => "4.1.77-1.1", "arch" => "x86_64" - ) + } end let(:selected_package2) do - Y2Packager::Resolvable.new( + { "name" => "yast2-pkg-bindings", "version" => "4.1.2-3.5.9", "arch" => "x86_64" - ) + } end it "reports an error for all packages" do diff --git a/test/old_package_test.rb b/test/old_package_test.rb index e5b4b8bc9..3232d52eb 100644 --- a/test/old_package_test.rb +++ b/test/old_package_test.rb @@ -20,7 +20,7 @@ context "no package is selected" do before do - expect(Y2Packager::Resolvable).to receive(:find).and_return([]) + expect(Yast::Pkg).to receive(:ResolvableProperties).and_return([]) end it "returns nil" do @@ -29,22 +29,26 @@ end context "an old package is selected" do - let(:old_package) { Y2Packager::Resolvable.new("name" => "yast2", "version" => "4.1.69-1.2") } + let(:old_package) do + { "name" => "yast2", "version" => "4.1.69-1.2", "arch" => "x86_64", "status" => :selected } + end before do - expect(Y2Packager::Resolvable).to receive(:find).and_return([old_package]) + expect(Yast::Pkg).to receive(:ResolvableProperties).and_return([old_package]) end it "returns the old package Resolvable" do - expect(subject.selected_old).to be(old_package) + expect(subject.selected_old).to eq(old_package) end end context "a new package is selected" do - let(:new_package) { Y2Packager::Resolvable.new("name" => "yast2", "version" => "4.1.99-1.2") } + let(:new_package) do + { "name" => "yast2", "version" => "4.1.99-1.2", "arch" => "x86_64", "status" => :selected } + end before do - expect(Y2Packager::Resolvable).to receive(:find).and_return([new_package]) + expect(Yast::Pkg).to receive(:ResolvableProperties).and_return([new_package]) end it "returns nil" do From a5ecbe884fedf4fa595ccc012623dc154c00a6bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Tue, 28 Jul 2020 10:48:07 +0200 Subject: [PATCH 3/6] Adapt .spec file --- package/yast2-installation.spec | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package/yast2-installation.spec b/package/yast2-installation.spec index 4d14267e2..8e07d2633 100644 --- a/package/yast2-installation.spec +++ b/package/yast2-installation.spec @@ -214,6 +214,9 @@ systemctl enable YaST2-Firstboot.service %files %defattr(-,root,root) +# data files +%{yast_ydatadir} + # systemd service files %{_unitdir}/YaST2-Second-Stage.service %{_unitdir}/YaST2-Firstboot.service From 9df4432151af8b2e8a33c17e1657525065fcba58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Tue, 28 Jul 2020 13:38:59 +0200 Subject: [PATCH 4/6] More comments, added test --- src/lib/installation/old_package.rb | 9 +++++++++ src/lib/installation/old_package_check.rb | 2 ++ src/lib/installation/old_package_report.rb | 2 ++ test/old_package_check_test.rb | 15 +++++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 test/old_package_check_test.rb diff --git a/src/lib/installation/old_package.rb b/src/lib/installation/old_package.rb index 30923e446..2f85cf52a 100644 --- a/src/lib/installation/old_package.rb +++ b/src/lib/installation/old_package.rb @@ -23,6 +23,11 @@ class OldPackage attr_reader :name, :version, :arch, :message + # @param name [String] name of the package + # @param version [String] version of the package + # @param arch [String] architecture, e.g. "x86_64" + # @param message [String] the error message displayed to the user + # when an old package is selected def initialize(name:, version:, arch:, message:) @name = name @version = version @@ -30,6 +35,8 @@ def initialize(name:, version:, arch:, message:) @message = message end + # Finds the currently selected old package, if none or newer is selected then + # it returns `nil`. # @return [Hash,nil] The selected old package or nil. def selected_old packages = Yast::Pkg.ResolvableProperties(name, :package, "") @@ -43,6 +50,8 @@ def selected_old # Reads the old package configuration files and creates the respective # OldPackage objects. + # @return [Array] Configured old packages, empty list if no configuration + # is specified def self.read(paths = nil) # unfortunately we cannot use Yast::Directory.find_data_file # here because it needs an exact file name, it does not accept a glob, diff --git a/src/lib/installation/old_package_check.rb b/src/lib/installation/old_package_check.rb index dedf51128..1048dc977 100644 --- a/src/lib/installation/old_package_check.rb +++ b/src/lib/installation/old_package_check.rb @@ -19,6 +19,8 @@ module Installation # This class checks whether some old packages are selected # and displays a warning to the user. class OldPackageCheck + # Read the old package configurations and display warning for the old selected + # packages. def self.run old_packages = OldPackage.read reporter = OldPackageReport.new(old_packages) diff --git a/src/lib/installation/old_package_report.rb b/src/lib/installation/old_package_report.rb index 10d67dfe0..01dbe76bd 100644 --- a/src/lib/installation/old_package_report.rb +++ b/src/lib/installation/old_package_report.rb @@ -24,11 +24,13 @@ class OldPackageReport attr_reader :old_packages + # @param old_packages [Array] old package configurations def initialize(old_packages) textdomain "installation" @old_packages = old_packages end + # report the selected old packages to the user def report report_packages = old_packages.select(&:selected_old) if report_packages.empty? diff --git a/test/old_package_check_test.rb b/test/old_package_check_test.rb new file mode 100644 index 000000000..bae4ff48c --- /dev/null +++ b/test/old_package_check_test.rb @@ -0,0 +1,15 @@ +#! /usr/bin/env rspec + +require_relative "test_helper" + +require "installation/old_package_check" + +describe Installation::OldPackageCheck do + describe ".run" do + it "reads old package configurations and reports the old packages" do + expect(Installation::OldPackage).to receive(:read) + expect_any_instance_of(Installation::OldPackageReport).to receive(:report) + Installation::OldPackageCheck.run + end + end +end From fb03e533d7c65ea3615c1098c187aa93d5f41bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Tue, 4 Aug 2020 17:20:40 +0200 Subject: [PATCH 5/6] Code review fixes --- src/lib/installation/clients/inst_doit.rb | 4 ++-- src/lib/installation/old_package.rb | 14 +++++++++----- ...old_package_check.rb => old_package_checker.rb} | 6 +++--- ...d_package_report.rb => old_package_reporter.rb} | 4 ++-- ...e_check_test.rb => old_package_checker_test.rb} | 8 ++++---- ...report_test.rb => old_package_reporter_test.rb} | 6 +++--- test/old_package_test.rb | 14 ++++++++++++++ 7 files changed, 37 insertions(+), 19 deletions(-) rename src/lib/installation/{old_package_check.rb => old_package_checker.rb} (89%) rename src/lib/installation/{old_package_report.rb => old_package_reporter.rb} (95%) rename test/{old_package_check_test.rb => old_package_checker_test.rb} (51%) rename test/{old_package_report_test.rb => old_package_reporter_test.rb} (93%) diff --git a/src/lib/installation/clients/inst_doit.rb b/src/lib/installation/clients/inst_doit.rb index 12085ba5d..69b3a085b 100644 --- a/src/lib/installation/clients/inst_doit.rb +++ b/src/lib/installation/clients/inst_doit.rb @@ -19,7 +19,7 @@ # current contact information at www.novell.com. # ------------------------------------------------------------------------------ -require "installation/old_package_check" +require "installation/old_package_checker" module Yast # Asks user to really do the installation/update. @@ -44,7 +44,7 @@ def main PackagesUI.ConfirmLicenses # warn about installing old packages - ::Installation::OldPackageCheck.run + ::Installation::OldPackageChecker.run # function in installation/misc.ycp # bugzilla #219097 diff --git a/src/lib/installation/old_package.rb b/src/lib/installation/old_package.rb index 2f85cf52a..530196283 100644 --- a/src/lib/installation/old_package.rb +++ b/src/lib/installation/old_package.rb @@ -41,17 +41,21 @@ def initialize(name:, version:, arch:, message:) def selected_old packages = Yast::Pkg.ResolvableProperties(name, :package, "") - # 1 = the selected is newer, the opposite is older or the same + # -1 = the second version (the selected package) is newer packages.find do |p| p["status"] == :selected && p["arch"] == arch && - Yast::Pkg.CompareVersions(version, p["version"]) == 1 + Yast::Pkg.CompareVersions(version, p["version"]) != -1 end end # Reads the old package configuration files and creates the respective - # OldPackage objects. - # @return [Array] Configured old packages, empty list if no configuration - # is specified + # OldPackage objects. It reads all YAML files from the subdirectories. + # @param paths [Array,nil] The list of directories which are scanned + # for the YAML configuration files. If `nil` then the default YaST paths + # are used. + # @return [Array] Configured old packages, + # empty list if no configuration is specified + # @see See the data/old_packages/*.yml example file. def self.read(paths = nil) # unfortunately we cannot use Yast::Directory.find_data_file # here because it needs an exact file name, it does not accept a glob, diff --git a/src/lib/installation/old_package_check.rb b/src/lib/installation/old_package_checker.rb similarity index 89% rename from src/lib/installation/old_package_check.rb rename to src/lib/installation/old_package_checker.rb index 1048dc977..a9b07a78c 100644 --- a/src/lib/installation/old_package_check.rb +++ b/src/lib/installation/old_package_checker.rb @@ -12,18 +12,18 @@ require "yast" -require "installation/old_package_report" +require "installation/old_package_reporter" require "installation/old_package" module Installation # This class checks whether some old packages are selected # and displays a warning to the user. - class OldPackageCheck + class OldPackageChecker # Read the old package configurations and display warning for the old selected # packages. def self.run old_packages = OldPackage.read - reporter = OldPackageReport.new(old_packages) + reporter = OldPackageReporter.new(old_packages) reporter.report end end diff --git a/src/lib/installation/old_package_report.rb b/src/lib/installation/old_package_reporter.rb similarity index 95% rename from src/lib/installation/old_package_report.rb rename to src/lib/installation/old_package_reporter.rb index 01dbe76bd..d62ba0ed7 100644 --- a/src/lib/installation/old_package_report.rb +++ b/src/lib/installation/old_package_reporter.rb @@ -18,7 +18,7 @@ module Installation # This class checks whether some old packages are selected # and displays a warning to the user. - class OldPackageReport + class OldPackageReporter include Yast::Logger include Yast::I18n @@ -55,7 +55,7 @@ def report end message = format(_("The installer detected old package versions selected " \ - "for installation: \n\n%{list}"), list: pkg_summary) + "for installation: %{list}"), list: pkg_summary) Yast::Report.LongWarning(message) end diff --git a/test/old_package_check_test.rb b/test/old_package_checker_test.rb similarity index 51% rename from test/old_package_check_test.rb rename to test/old_package_checker_test.rb index bae4ff48c..bc1fd65a3 100644 --- a/test/old_package_check_test.rb +++ b/test/old_package_checker_test.rb @@ -2,14 +2,14 @@ require_relative "test_helper" -require "installation/old_package_check" +require "installation/old_package_checker" -describe Installation::OldPackageCheck do +describe Installation::OldPackageChecker do describe ".run" do it "reads old package configurations and reports the old packages" do expect(Installation::OldPackage).to receive(:read) - expect_any_instance_of(Installation::OldPackageReport).to receive(:report) - Installation::OldPackageCheck.run + expect_any_instance_of(Installation::OldPackageReporter).to receive(:report) + Installation::OldPackageChecker.run end end end diff --git a/test/old_package_report_test.rb b/test/old_package_reporter_test.rb similarity index 93% rename from test/old_package_report_test.rb rename to test/old_package_reporter_test.rb index 8ffd250ce..f3032f1bd 100644 --- a/test/old_package_report_test.rb +++ b/test/old_package_reporter_test.rb @@ -3,9 +3,9 @@ require_relative "test_helper" require "installation/old_package" -require "installation/old_package_report" +require "installation/old_package_reporter" -describe Installation::OldPackageReport do +describe Installation::OldPackageReporter do let(:message1) { "These packages are too old, install new ones." } let(:message2) { "This package contains a bug." } let(:old_package1) do @@ -25,7 +25,7 @@ ) end - subject { Installation::OldPackageReport.new([old_package1, old_package2]) } + subject { Installation::OldPackageReporter.new([old_package1, old_package2]) } describe "#report" do before do diff --git a/test/old_package_test.rb b/test/old_package_test.rb index 3232d52eb..9df831e53 100644 --- a/test/old_package_test.rb +++ b/test/old_package_test.rb @@ -55,5 +55,19 @@ expect(subject.selected_old).to be_nil end end + + context "a package with the same version is selected" do + let(:old_package) do + { "name" => "yast2", "version" => subject.version, "arch" => "x86_64", "status" => :selected } + end + + before do + expect(Yast::Pkg).to receive(:ResolvableProperties).and_return([old_package]) + end + + it "returns the package Resolvable" do + expect(subject.selected_old).to eq(old_package) + end + end end end From 57c1e6a167884246a24b838f60b79ea045aebf32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Tue, 4 Aug 2020 17:21:08 +0200 Subject: [PATCH 6/6] Display the warning also in the AutoYaSt mode --- src/lib/installation/clients/inst_doit.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/installation/clients/inst_doit.rb b/src/lib/installation/clients/inst_doit.rb index 69b3a085b..2cca45dd0 100644 --- a/src/lib/installation/clients/inst_doit.rb +++ b/src/lib/installation/clients/inst_doit.rb @@ -37,15 +37,15 @@ def main Yast.include self, "installation/misc.rb" + # warn about installing old packages (also in the AutoYaST mode) + ::Installation::OldPackageChecker.run + return :next if Mode.autoinst && !AutoinstConfig.Confirm # old functionality replaced with this function-call # bugzilla #256627 PackagesUI.ConfirmLicenses - # warn about installing old packages - ::Installation::OldPackageChecker.run - # function in installation/misc.ycp # bugzilla #219097 @confirmed = confirmInstallation