Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PackageSystem.Installed: Improve loging details #938

Merged
merged 3 commits into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions library/packages/src/modules/PackageSystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

module Yast
class PackageSystemClass < Module
include Yast::Logger

def main
Yast.import "Pkg"
textdomain "base"
Expand Down Expand Up @@ -335,22 +337,22 @@ def InitRPMQueryBinary
end

# Is a package provided in the system? Is there any installed package providing 'package'?
# @return true if yes
#
# @param package [String] name of the package to check if provided
# @return [Boolean] whether the package is provided in the system or not
def Installed(package)
# This is a most commonly called function and so it's
# important that it's fast, especially in the common
# case, where all dependencies are satisfied.
# Unfortunately, initializing Pkg reads the RPM database...
# so we must avoid it.
# added --whatprovides due to bug #76181
0 ==
Convert.to_integer(
SCR.Execute(
path(".target.bash"),
Ops.add("/usr/bin/rpm -q --whatprovides ", package.shellescape)
)
)
rpm_command = "/usr/bin/rpm -q --whatprovides #{package.shellescape}"
output = SCR.Execute(path(".target.bash_output"), rpm_command)
log.info "Query installed package with '#{rpm_command}' and result #{output.inspect}"

# return Pkg::IsProvided (package);
output["exit"] == 0
end

# Is a package installed? Checks only the package name in contrast to Installed() function.
Expand Down
32 changes: 32 additions & 0 deletions library/packages/test/package_system_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,38 @@
describe "Yast::PackageSystem" do
subject(:system) { Yast::PackageSystem }

describe "#Install" do
let(:package) { "ruby" }
let(:package_installed) { "ruby-2.5-lp150.1.5.x86_64" }
let(:bash_output) do
{ "exit" => 1, "stderr" => "", "stdout" => "no package prodives #{package}\n" }
end
let(:installed) do
end

before do
allow(Yast::SCR).to receive(:Execute)
.with(Yast::Path.new(".target.bash_output"), /rpm -q --whatprovides #{package}/)
.and_return(bash_output)
end

context "when some package provides the given package" do
let(:bash_output) do
{ "exit" => 0, "stderr" => "", "stdout" => "#{package_installed}\n" }
end

it "returns true" do
expect(system.Installed("ruby")).to be(true)
end
end

context "when no package provides the given package" do
it "returns false" do
expect(system.Installed("ruby")).to be(false)
end
end
end

describe "DoInstallAndRemove" do
let(:lock_free) { true }
let(:result) { [1, [], [], [], []] }
Expand Down
7 changes: 7 additions & 0 deletions package/yast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Jun 13 11:56:37 UTC 2019 - Knut Anderssen <kanderssen@suse.com>

- bsc#1137992
- PackageSystem.Installed: Increase the logs details.
- 4.2.7

-------------------------------------------------------------------
Wed Jun 5 10:44:18 UTC 2019 - Knut Anderssen <kanderssen@suse.de>

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


Name: yast2
Version: 4.2.6
Version: 4.2.7
Release: 0
Summary: YaST2 Main Package
License: GPL-2.0-only
Expand Down