diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-04-05 20:58:24 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-04-05 20:58:24 +0000 |
| commit | 4ab74ce60963eb543c5e2aa4bb3bd696bf2a5438 (patch) | |
| tree | 1b0b2171fdf1fb61567638d899423864857c282b | |
| parent | 50ffa7f6b0885e2fb2e1e468c04dfec81f21e011 (diff) | |
| download | puppet-4ab74ce60963eb543c5e2aa4bb3bd696bf2a5438.tar.gz puppet-4ab74ce60963eb543c5e2aa4bb3bd696bf2a5438.tar.xz puppet-4ab74ce60963eb543c5e2aa4bb3bd696bf2a5438.zip | |
Fixing checks so that they can run even if the set cwd does not exist
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1087 980ebf18-57e1-0310-9a29-db15c13687c0
| -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 |
