Skip to content

Commit

Permalink
Make virtual package prefer the Depends: if listed
Browse files Browse the repository at this point in the history
  • Loading branch information
Toomas Pelberg authored and danielsdeleo committed Aug 26, 2010
1 parent ab9991d commit c464f5f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions chef/lib/chef/provider/package/apt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def load_current_resource
def installed?(package=@new_resource.package_name)
Chef::Log.debug("Checking package status for #{package}")
installed = false
depends = false

status = shell_out!("aptitude show #{package}")
status.stdout.each do |line|
Expand All @@ -51,11 +52,15 @@ def installed?(package=@new_resource.package_name)
else
@current_resource.version(nil)
end
when /Depends: (.*)$/
depends = $1
when /Provided by: ([\w\d\-\.]*)/
Chef::Log.debug("Virtual package provided by #{$1}")
virtual_provider = $1
virtual_provider = depends if depends
Chef::Log.debug("Virtual package provided by #{virtual_provider}")
@virtual = true
installed = installed?($1)
@candidate_version = $1
installed = installed?(virtual_provider)
@candidate_version = virtual_provider
end
end

Expand Down
4 changes: 2 additions & 2 deletions chef/spec/unit/provider/package/apt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@
@provider.candidate_version.should eql("libmysqlclient15-dev")
end

it "should set candidate version to the first package name if multiple virtual package providers" do
it "should set candidate version to the depends package name if multiple virtual package providers" do
@new_resource.package_name("mysql-client")
virtual_package_out=mock("STDOUT", :null_object => true)
virtual_package_out.stub!(:each).and_yield("Package: mysql-client").
and_yield("State: not installed").
and_yield("Version: 5.1.41-3ubuntu12.6").
and_yield("Depends: mysql-client-5.1").
and_yield("Provided by: mysql-client-5.1, mysql-cluster-client-5.1").
and_yield("Provided by: mysql-cluster-client-5.1, mysql-client-5.1").
and_yield("Description: MySQL database client (metapackage depending on the latest version)")
virtual_package = mock(:stdout => virtual_package_out,:exitstatus => 0)
@provider.should_receive(:shell_out!).with("aptitude show mysql-client").and_return(virtual_package)
Expand Down

0 comments on commit c464f5f

Please sign in to comment.