Skip to content

Commit

Permalink
Merge pull request #942 from yast/yast_execute
Browse files Browse the repository at this point in the history
* PackageSystem.Installed: Use Yast::Execute instead of SCR

* Bump version & changelog.
  • Loading branch information
teclator committed Jun 20, 2019
2 parents 73ffca1 + a5cdc19 commit 3707e2f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
12 changes: 8 additions & 4 deletions library/packages/src/modules/PackageSystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
# The documentation is maintained at
# <a href="../index.html">.../docs/index.html</a>.
require "yast"
require "yast2/execute"
require "shellwords"

module Yast
Expand Down Expand Up @@ -347,12 +348,15 @@ def Installed(package)
# Unfortunately, initializing Pkg reads the RPM database...
# so we must avoid it.
# added --whatprovides due to bug #76181
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}"
# Use Yast::Execute to prevent false positives (boo#1137992)
rpm_command = ["/usr/bin/rpm", "-q", "--whatprovides", package]
# We are not raising exceptions in case of return codes different than
# 0 or 1. So do not plan to modify the current behavior.
output, return_code = Yast::Execute.stdout.on_target!(rpm_command, allow_exitstatus: 0..1)
log.info "Query installed package with '#{rpm_command.join(" ")}' and result #{output}"

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

# Is a package installed? Checks only the package name in contrast to Installed() function.
Expand Down
17 changes: 5 additions & 12 deletions library/packages/test/package_system_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,22 @@
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
let(:output) { [package_installed, 0] }
let(:execute) { instance_double(Yast::Execute, on_target!: output) }

before do
allow(Yast::SCR).to receive(:Execute)
.with(Yast::Path.new(".target.bash_output"), /rpm -q --whatprovides #{package}/)
.and_return(bash_output)
allow(Yast::Execute).to receive(:stdout).and_return(execute)
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
let(:output) { ["no package provides ruby\n", 1] }

it "returns false" do
expect(system.Installed("ruby")).to be(false)
end
Expand Down
8 changes: 8 additions & 0 deletions package/yast2.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
-------------------------------------------------------------------
Wed Jun 19 08:30:04 UTC 2019 - Knut Anderssen <kanderssen@suse.com>

- bsc#1137992
- PackageSystem.Installed: Use Yast::Execute instead of SCR
to avoid false positives.
- 4.2.9

-------------------------------------------------------------------
Tue Jun 18 09:06:13 CEST 2019 - schubi@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.8
Version: 4.2.9
Release: 0
Summary: YaST2 Main Package
License: GPL-2.0-only
Expand Down

0 comments on commit 3707e2f

Please sign in to comment.