diff options
-rwxr-xr-x | lib/puppet/type/exec.rb | 11 | ||||
-rwxr-xr-x | test/types/exec.rb | 34 |
2 files changed, 41 insertions, 4 deletions
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index a7d637e57..6fec43520 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -128,6 +128,12 @@ 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"] @@ -248,10 +254,6 @@ module Puppet if dir.is_a?(Array) dir = dir[0] end - - unless File.directory?(dir) - self.fail "Directory '%s' does not exist" % dir - end dir end @@ -391,6 +393,7 @@ module Puppet validatecmd(self[:command]) end + # FIXME exec should autorequire any exec that 'creates' our cwd autorequire(:file) do reqs = [] diff --git a/test/types/exec.rb b/test/types/exec.rb index f776dbd3b..782f1a871 100755 --- a/test/types/exec.rb +++ b/test/types/exec.rb @@ -449,6 +449,40 @@ class TestExec < Test::Unit::TestCase end end end + + def test_createcwdandexe + exec1 = exec2 = nil + dir = tempfile() + file = tempfile() + + assert_nothing_raised { + exec1 = Puppet.type(:exec).create( + :path => ENV["PATH"], + :command => "mkdir #{dir}" + ) + } + + assert_nothing_raised("Could not create exec w/out existing cwd") { + exec2 = Puppet.type(:exec).create( + :path => ENV["PATH"], + :command => "touch #{file}", + :cwd => dir + ) + } + + assert_raise(Puppet::Error) do + exec2.state(:returns).sync + end + + assert_nothing_raised do + exec2[:require] = ["exec", exec1.name] + exec2.finish + end + + assert_apply(exec1, exec2) + + assert(FileTest.exists?(file)) + end end # $Id$ |