From 1e4abaeccaef620f7e44b21479d5c9ea52c3360a Mon Sep 17 00:00:00 2001 From: luke Date: Wed, 5 Apr 2006 20:27:27 +0000 Subject: moving cwd existence check into "sync" instead of "validate" git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1085 980ebf18-57e1-0310-9a29-db15c13687c0 --- lib/puppet/type/exec.rb | 11 +++++++---- 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$ -- cgit