summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2015-06-06 14:58:17 +0200
committerThom May <thom@chef.io>2015-08-12 15:30:06 +0100
commit062dad8a42669e2b90c54d0a32511dbd01842a38 (patch)
tree73f0d90adf8169fb6aba9e1b8c5a3d1b3ded490d
parent2999d552880ff8fe2d056f89205114ab7c3c9979 (diff)
downloadchef-tm/use-dpkg-deb.tar.gz
Use the output of dpkg-deb directly, rather than regextm/use-dpkg-deb
Thanks to @kwilczynski for the original implementation
-rw-r--r--CHANGELOG.md7
-rw-r--r--lib/chef/provider/package/dpkg.rb16
-rw-r--r--spec/unit/provider/package/dpkg_spec.rb9
3 files changed, 17 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4b6121765b..7fae267d8d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,15 +2,15 @@
* [**Ranjib Dey**](https://github.com/ranjib):
[pr#3588](https://github.com/chef/chef/pull/3588) Count skipped resources among total resources in doc formatter
* [**John Kerry**](https://github.com/jkerry):
- [pr#3539](https://github.com/chef/chef/pull/3539) Fix issue: registry_key resource is case sensitive in chef but not on windows
+ [pr#3539](https://github.com/chef/chef/pull/3539) Fix issue: registry\_key resource is case sensitive in chef but not on windows
* [**David Eddy**](https://github.com/bahamas10):
[pr#3443](https://github.com/chef/chef/pull/3443) remove extraneous space
-* [pr#3455](https://github.com/chef/chef/pull/3455) powershell_script: do not allow suppression of syntax errors
+* [pr#3455](https://github.com/chef/chef/pull/3455) powershell\_script: do not allow suppression of syntax errors
* [pr#3519](https://github.com/chef/chef/pull/3519) The wording seemed odd.
* [pr#3208](https://github.com/chef/chef/pull/3208) Missing require (require what you use).
-* [pr#3449](https://github.com/chef/chef/pull/3449) correcting minor typo in user_edit knife action
+* [pr#3449](https://github.com/chef/chef/pull/3449) correcting minor typo in user\_edit knife action
* [pr#3572](https://github.com/chef/chef/pull/3572) Use windows paths without case-sensitivity.
* [pr#3666](https://github.com/chef/chef/pull/3666) Support SNI in `knife ssl check`.
* [pr#3667](https://github.com/chef/chef/pull/3667) Change chef service to start as 'Automatic delayed start'.
@@ -18,6 +18,7 @@
* [pr#3698](https://github.com/chef/chef/pull/3698) Add ability to specify dependencies in chef-service-manager.
* [pr#3728](https://github.com/chef/chef/pull/3728) Rewrite NetLocalGroup things to use FFI
* [pr#3754](https://github.com/chef/chef/pull/3754) Fix functional tests for group resource - fix #3728
+* [pr#3498](https://github.com/chef/chef/pull/3498) Use dpkg-deb directly rather than regex
## 12.4.1
diff --git a/lib/chef/provider/package/dpkg.rb b/lib/chef/provider/package/dpkg.rb
index a262f1ab1a..67e9b903c6 100644
--- a/lib/chef/provider/package/dpkg.rb
+++ b/lib/chef/provider/package/dpkg.rb
@@ -25,8 +25,6 @@ class Chef
class Provider
class Package
class Dpkg < Chef::Provider::Package
- # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version
- DPKG_INFO = /([a-z\d\-\+\.]+)\t([\w\d.~:-]+)/
DPKG_INSTALLED = /^Status: install ok installed/
DPKG_VERSION = /^Version: (.+)$/
@@ -54,26 +52,22 @@ class Chef
@source_exists = true
@current_resource = Chef::Resource::Package.new(@new_resource.name)
@current_resource.package_name(@new_resource.package_name)
- @new_resource.version(nil)
if @new_resource.source
@source_exists = ::File.exists?(@new_resource.source)
if @source_exists
# Get information from the package if supplied
Chef::Log.debug("#{@new_resource} checking dpkg status")
-
- shell_out_with_timeout("dpkg-deb -W #{@new_resource.source}").stdout.each_line do |line|
- if pkginfo = DPKG_INFO.match(line)
- @current_resource.package_name(pkginfo[1])
- @new_resource.version(pkginfo[2])
- @candidate_version = pkginfo[2]
- end
+ status = shell_out_with_timeout("dpkg-deb -W #{@new_resource.source}")
+ pkginfo = status.stdout.split("\t")
+ unless pkginfo.empty?
+ @current_resource.package_name(pkginfo[0])
+ @candidate_version = pkginfo[1].strip
end
else
# Source provided but not valid means we can't safely do further processing
return
end
-
end
# Check to see if it is installed
diff --git a/spec/unit/provider/package/dpkg_spec.rb b/spec/unit/provider/package/dpkg_spec.rb
index 4974cff934..b868128147 100644
--- a/spec/unit/provider/package/dpkg_spec.rb
+++ b/spec/unit/provider/package/dpkg_spec.rb
@@ -54,7 +54,6 @@ describe Chef::Provider::Package::Dpkg do
allow(@provider).to receive(:shell_out).with("dpkg-deb -W #{@new_resource.source}", timeout: 900).and_return(@status)
@provider.load_current_resource
expect(@provider.current_resource.package_name).to eq("wget")
- expect(@new_resource.version).to eq(version)
expect(@provider.candidate_version).to eq(version)
end
@@ -83,6 +82,14 @@ describe Chef::Provider::Package::Dpkg do
expect(@provider.current_resource.package_name).to eq("f.o.o-pkg++2")
end
+ it "gets the source package version from dpkg-deb correctly when the package version has `~', `-', `+' or `.' characters" do
+ stdout = "b.a.r-pkg++1\t1.2.3+3141592-1ubuntu1~lucid"
+ status = double(:stdout => stdout, :exitstatus => 1)
+ allow(@provider).to receive(:shell_out).and_return(status)
+ @provider.load_current_resource
+ expect(@provider.candidate_version).to eq('1.2.3+3141592-1ubuntu1~lucid')
+ end
+
it "should raise an exception if the source is not set but we are installing" do
@new_resource = Chef::Resource::Package.new("wget")
@provider.new_resource = @new_resource