diff options
| -rwxr-xr-x | lib/puppet/type/exec.rb | 24 | ||||
| -rwxr-xr-x | test/types/exec.rb | 5 |
2 files changed, 21 insertions, 8 deletions
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index 0f4e42bcd..6c15e1c7f 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -128,12 +128,6 @@ module Puppet self.checkexe - if cwd = self.parent[:cwd] - unless File.directory?(cwd) - self.fail "Working directory '%s' does not exist" % cwd - end - end - # We need a dir to change to, even if it's just the cwd dir = self.parent[:cwd] || Dir.pwd tmppath = ENV["PATH"] @@ -449,11 +443,25 @@ module Puppet end # Run a command. - def run(command) + def run(command, check = false) output = nil status = nil tmppath = ENV["PATH"] - dir = self[:cwd] || Dir.pwd + + dir = nil + + if dir = self[:cwd] + unless File.directory?(dir) + if check + dir = nil + else + self.fail "Working directory '%s' does not exist" % dir + end + end + end + + dir ||= Dir.pwd + debug "Executing '#{command}'" begin # Do our chdir diff --git a/test/types/exec.rb b/test/types/exec.rb index 782f1a871..730562a95 100755 --- a/test/types/exec.rb +++ b/test/types/exec.rb @@ -470,6 +470,11 @@ class TestExec < Test::Unit::TestCase ) } + # Throw a check in there with our cwd and make sure it works + assert_nothing_raised("Could not check with a missing cwd") do + exec2[:unless] = "test -f /this/file/does/not/exist" + end + assert_raise(Puppet::Error) do exec2.state(:returns).sync end |
