Browse files

(GH-139) Throw away STDERR from dpkg-query in Fact

Newer versions of dpkg-query, as of Ubuntu 12.10, will make noise on STDERR
if the queried package isn't currently installed. Facter's `exec()` outputs
this without giving us a chance to catch it.

Pipe STDERR to `/dev/null` so that it's not seen by the end-user. STDOUT
will still be `nil` if the package isn't installed. It doesn't seem
reasonable to spec test for this without reaching deep into Facter, so I'm
not going to.
  • Loading branch information...
1 parent 841be58 commit 7c1ebd1d339ac73fb3b4f7c74b8fb9587d4244c7 @dcarley dcarley committed Mar 4, 2013
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/facter/iptables_persistent_version.rb
4 lib/facter/iptables_persistent_version.rb
@@ -1,7 +1,9 @@
Facter.add(:iptables_persistent_version) do
confine :operatingsystem => %w{Debian Ubuntu}
setcode do
- cmd = "dpkg-query -Wf '${Version}' iptables-persistent"
+ # Throw away STDERR because dpkg >= 1.16.7 will make some noise if the
+ # package isn't currently installed.
+ cmd = "dpkg-query -Wf '${Version}' iptables-persistent 2>/dev/null"
version = Facter::Util::Resolution.exec(cmd)
if version.nil? or !version.match(/\d+\.\d+/)

0 comments on commit 7c1ebd1

Please sign in to comment.