Skip to content

Commit

Permalink
Fix apt_has_updates fact not parsing apt-check output correctly
Browse files Browse the repository at this point in the history
The /usr/lib/update-notifier/apt-check script returns its output
to STDERR but a recent change to the script redirects STDERR to
/dev/null.  This will cause the array to always be empty.

Combined with that problem, while we were checking for the result
being nil, we never checked for an invalid array.  As a result,
the apt_has_updates was always true and the apt_updates and
apt_security_updates facts were trying to read from an empty array
and failing.
  • Loading branch information
WolverineFan committed Jan 15, 2015
1 parent 6d60659 commit cf7735f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/facter/apt_updates.rb
Expand Up @@ -2,18 +2,18 @@
Facter.add("apt_has_updates") do
confine :osfamily => 'Debian'
if File.executable?("/usr/lib/update-notifier/apt-check")
apt_package_updates = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check 2>/dev/null').split(';')
apt_package_updates = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check 2>&1').split(';')
end

setcode do
apt_package_updates != ['0', '0'] unless apt_package_updates.nil?
apt_package_updates != ['0', '0'] unless apt_package_updates.nil? or apt_package_updates.length != 2
end
end

Facter.add("apt_package_updates") do
confine :apt_has_updates => true
setcode do
packages = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check -p 2>/dev/null').split("\n")
packages = Facter::Util::Resolution.exec('/usr/lib/update-notifier/apt-check -p 2>&1').split("\n")
if Facter.version < '2.0.0'
packages.join(',')
else
Expand Down

0 comments on commit cf7735f

Please sign in to comment.