summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlutter <lutter@1f5c1d6a-bddf-0310-8f58-fc49e503516a>2006-11-08 19:52:34 +0000
committerlutter <lutter@1f5c1d6a-bddf-0310-8f58-fc49e503516a>2006-11-08 19:52:34 +0000
commit4dc1c37a0738157d796164b26fa68e16b6cf0b86 (patch)
tree4fb0ad3e3cd930e738f6cdcec8d805407e7d0a2d
parentc7a9e198fcf07d6d89bf274602574a88aa7f7dca (diff)
downloadfacter-4dc1c37a0738157d796164b26fa68e16b6cf0b86.tar.gz
facter-4dc1c37a0738157d796164b26fa68e16b6cf0b86.tar.xz
facter-4dc1c37a0738157d796164b26fa68e16b6cf0b86.zip
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
-rw-r--r--lib/facter.rb33
1 files 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