[Pkg-puppet-devel] [facter] 254/352: (FACT-322) Remove execution empty string special casing

Stig Sandbeck Mathisen ssm at debian.org
Sun Apr 6 22:21:50 UTC 2014


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository facter.

commit 41e766e5fb4a478f407c041c469f0bdf8633584b
Author: Adrien Thebo <git at somethingsinistral.net>
Date:   Thu Feb 13 13:55:26 2014 -0800

    (FACT-322) Remove execution empty string special casing
    
    This removes the special casing for commands that return the empty
    string. Callers that were checking the result of .exec with a boolean
    check will need to call #empty? on the result.
---
 lib/facter/core/execution.rb  |  8 ++------
 lib/facter/util/resolution.rb |  8 +-------
 lib/facter/util/uptime.rb     | 11 ++++++++---
 3 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/lib/facter/core/execution.rb b/lib/facter/core/execution.rb
index f500a9a..3b99486 100644
--- a/lib/facter/core/execution.rb
+++ b/lib/facter/core/execution.rb
@@ -168,7 +168,7 @@ module Facter
             return nil
           end
 
-          out = nil
+          out = ''
 
           begin
             out = %x{#{code}}.chomp
@@ -177,11 +177,7 @@ module Facter
             return nil
           end
 
-          if out == ""
-            return nil
-          else
-            return out
-          end
+          out
         end
       end
     end
diff --git a/lib/facter/util/resolution.rb b/lib/facter/util/resolution.rb
index ae9ccb2..336e7c6 100644
--- a/lib/facter/util/resolution.rb
+++ b/lib/facter/util/resolution.rb
@@ -129,13 +129,7 @@ class Facter::Util::Resolution
     if string
       @code = Proc.new do
         output = Facter::Core::Execution.exec(string)
-        if output.nil?
-          nil
-        elsif output.empty?
-          nil
-        else
-          output
-        end
+        output.empty? ? nil : output
       end
     elsif block_given?
       @code = block
diff --git a/lib/facter/util/uptime.rb b/lib/facter/util/uptime.rb
index 8af2af2..4df1cb0 100644
--- a/lib/facter/util/uptime.rb
+++ b/lib/facter/util/uptime.rb
@@ -20,19 +20,24 @@ module Facter::Util::Uptime
   private
 
   def self.uptime_proc_uptime
-    if output = Facter::Core::Execution.exec("/bin/cat #{uptime_file} 2>/dev/null")
+    output = Facter::Core::Execution.exec("/bin/cat #{uptime_file} 2>/dev/null")
+
+    if not output.empty?
       output.chomp.split(" ").first.to_i
     end
   end
 
   def self.uptime_sysctl
-    if output = Facter::Core::Execution.exec("#{uptime_sysctl_cmd} 2>/dev/null")
+    output = Facter::Core::Execution.exec("#{uptime_sysctl_cmd} 2>/dev/null")
+    if not output.empty?
       compute_uptime(Time.at(output.match(/\d+/)[0].to_i))
     end
   end
 
   def self.uptime_executable
-    if output = Facter::Core::Execution.exec("#{uptime_executable_cmd} 2>/dev/null")
+    output = Facter::Core::Execution.exec("#{uptime_executable_cmd} 2>/dev/null")
+
+    if not output.empty?
       up=0
       if output =~ /(\d+) day(?:s|\(s\))?,\s+(\d+):(\d+)/
         # Regexp handles Solaris, AIX, HP-UX, and Tru64.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git



More information about the Pkg-puppet-devel mailing list