summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-01-02 06:54:05 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-01-02 06:54:05 +0000
commit57d093309f7fcc003cbd420133a8923e1174260c (patch)
tree339936405e40c85576eb68b1e5492ebadc6a63a2
parent0887fcdac1d2973f49de7022e1cc1882295d4aa3 (diff)
downloadpuppet-57d093309f7fcc003cbd420133a8923e1174260c.tar.gz
puppet-57d093309f7fcc003cbd420133a8923e1174260c.tar.xz
puppet-57d093309f7fcc003cbd420133a8923e1174260c.zip
Fixing #396. Using the provider command instead of a direct exec, which automatically captures stderr.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2014 980ebf18-57e1-0310-9a29-db15c13687c0
-rwxr-xr-xlib/puppet/provider/package/dpkg.rb43
1 files changed, 26 insertions, 17 deletions
diff --git a/lib/puppet/provider/package/dpkg.rb b/lib/puppet/provider/package/dpkg.rb
index 0e49f84aa..4b146c7d7 100755
--- a/lib/puppet/provider/package/dpkg.rb
+++ b/lib/puppet/provider/package/dpkg.rb
@@ -53,28 +53,37 @@ Puppet::Type.type(:package).provide :dpkg do
fields = [:desired, :error, :status, :name, :ensure]
hash = {}
+
# list out our specific package
- open("| #{command(:dpkgquery)} -W --showformat '${Status} ${Package} ${Version}\\n' %s" % @model[:name]) { |process|
- # our regex for matching dpkg-query output
- regex = %r{^(\S+) (\S+) (\S+) (\S+) (\S+)$}
-
- lines = process.readlines.collect {|l| l.chomp }
-
- line = lines[0]
-
- if match = regex.match(line)
- fields.zip(match.captures) { |field,value|
- hash[field] = value
- }
- else
- hash = {:ensure => :absent, :status => 'missing', :name => @model[:name], :error => 'ok'}
- end
- }
+ begin
+ output = dpkgquery("-W", "--showformat",
+ '${Status} ${Package} ${Version}\\n', @model[:name]
+ )
+ rescue Puppet::ExecutionFailure
+ # dpkg-query exits 1 if the package is not found.
+ return {:ensure => :absent, :status => 'missing',
+ :name => @model[:name], :error => 'ok'}
+
+ end
+ # Our regex for matching dpkg-query output. We could probably just
+ # use split here, but I'm not positive that dpkg-query will never
+ # return whitespace.
+ regex = %r{^(\S+) (\S+) (\S+) (\S+) (\S+)$}
+
+ line = output.split("\n").shift.chomp
+
+ if match = regex.match(line)
+ fields.zip(match.captures) { |field,value|
+ hash[field] = value
+ }
+ else
+ raise Puppet::DevError, "Failed to handle dpkg-query output"
+ end
if hash[:error] != "ok"
raise Puppet::PackageError.new(
"Package %s, version %s is in error state: %s" %
- [hash[:name], hash[:ensure], hash[:error]]
+ [hash[:name], hash[:ensure], hash[:error]]
)
end