Skip to content

Commit

Permalink
Merge pull request #938 from yast/package_provided_log
Browse files Browse the repository at this point in the history
PackageSystem.Installed: Improve loging details
  • Loading branch information
teclator committed Jun 14, 2019
2 parents 6f7a789 + ce86ff4 commit f4c1109
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
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

0 comments on commit f4c1109

Please sign in to comment.