From 4dc1c37a0738157d796164b26fa68e16b6cf0b86 Mon Sep 17 00:00:00 2001 From: lutter Date: Wed, 8 Nov 2006 19:52:34 +0000 Subject: Do not try and check the command if which is not available; fixes trac #30 git-svn-id: http://reductivelabs.com/svn/facter/trunk@182 1f5c1d6a-bddf-0310-8f58-fc49e503516a --- lib/facter.rb | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/lib/facter.rb b/lib/facter.rb index 7956585..11865cc 100644 --- a/lib/facter.rb +++ b/lib/facter.rb @@ -385,26 +385,37 @@ class Facter class Resolution attr_accessor :interpreter, :code, :name, :fact + def Resolution.have_which + if @have_which.nil? + %x{which which 2>/dev/null} + @have_which = ($? == 0) + end + @have_which + end + # Execute a chunk of code. def Resolution.exec(code, interpreter = "/bin/sh") if interpreter == "/bin/sh" binary = code.split(/\s+/).shift - path = nil - if binary !~ /^\// - path = %x{which #{binary} 2>/dev/null}.chomp - if path == "" - # we don't have the binary necessary + if have_which + path = nil + if binary !~ /^\// + path = %x{which #{binary} 2>/dev/null}.chomp + if path == "" + # we don't have the binary necessary + return nil + end + else + path = binary + end + + unless FileTest.exists?(path) + # our binary does not exist return nil end - else - path = binary end - unless FileTest.exists?(path) - # our binary does not exist - return nil - end out = nil begin out = %x{#{code}}.chomp -- cgit